【发布时间】:2018-03-03 16:44:42
【问题描述】:
void Update ()
{
Vector3 input = new Vector3 (0, 0, 1);
Vector3 direction = input.normalized;
Vector3 velocity = direction * speed;
Vector3 moveAmount = velocity * Time.deltaTime;
transform.position += moveAmount;
if(Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
player.AddForce (Vector3.up * jumpForce, ForceMode.Impulse);
}
}
由于Time.deltaTime 不同,moveAmount 也因每次跳跃而不同,因此跳跃的距离会略有不同。
球会在由固定间隙隔开的块之间跳跃,因此上述行为会导致问题。
有什么办法可以解决这个问题并进行固定长度的跳跃吗?
【问题讨论】:
-
不能保证刚体力总是相同的。要减少跳跃距离的差异,请从跳跃距离中删除
Time.deltaTime。你不需要那个。
标签: c# unity3d game-physics