d d*_*doe 7 c# unity-game-engine
目前,我的脚本是将玩家移动到场景周围.我怎样才能顺利移动?
void FixedUpdate()
{
bool running = Input.GetKey(KeyCode.LeftShift);
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
bool isWalking = Mathf.Abs(h) + Mathf.Abs(v) > 0;
movement = ((running) ? runSpeed : walkSpeed) * new Vector3(h, 0.0f, v).normalized;
if (isWalking)
{
transform.position += movement * Time.fixedDeltaTime;
transform.LookAt(transform.position + movement);
}
}
Run Code Online (Sandbox Code Playgroud)
Igg*_*ggy 10
创建速度矢量:
Vector3 velocity = Vector3.zero;
将您的运动矢量添加到力度:
velocity += movement;
将速度添加到实际位置:
transform.position += velocity;
通过随时间减少速度来平滑速度:
velocity *= 0.975f;
| 归档时间: |
|
| 查看次数: |
830 次 |
| 最近记录: |