【发布时间】:2021-02-18 15:14:33
【问题描述】:
因此,我和我的朋友们正在开发一款游戏,您可以在其中玩雪球滚下山坡,避开障碍物。然而,我们的运动遇到了麻烦。我们希望我们的雪球越快越快,越长越不会撞到任何东西。我们的前进是由
void FixedUpdate(){
rb.velocity += Physics.gravity * 3f * rb.mass * Time.deltaTime;
//to accelerate
rb.AddForce(0, 0, 32 * rb.mass);
}
我们正在对按键输入施加侧向力
if (Input.GetKey(ControlManager.CM.left))
{
if (rb.velocity.x >= -15 - (rb.mass * 8))
{
rb.AddForce(Vector3.left * sidewaysForce * (rb.mass * .5f), ForceMode.VelocityChange);
}
}
if (Input.GetKey(ControlManager.CM.right))
{
if (rb.velocity.x <= 15 + (rb.mass * 8))
{
rb.AddForce(Vector3.right * sidewaysForce * (rb.mass * .5f), ForceMode.VelocityChange);
}
}
质量随着规模的增加而增加,反之亦然。
当雪球变得大于一定规模时,问题就出现了。一旦达到该点,它就会在您按下按键时向左和向右大幅加速,然后在您松开时迅速恢复到其前进速度。我认为这与质量和施加的力复合的方式有关。
有没有更好的方法来加速我们的雪球下坡或左右移动?我尝试过 transform.Translate 和 transform.MovePosition,但它们会导致左右移动不连贯。
【问题讨论】:
标签: unity3d game-physics