如何修复玩家下落运动速度极慢的问题?
我发现了一个非常简单的运动脚本,可以在 Unity 3D 中运行。唯一的问题是玩家下落的速度非常慢(几乎没有)。我该如何解决这个问题?就好像它被某种东西减慢了速度,因为其他物体以正常速度下落。更改项目设置也不起作用。
C# 代码(分配给玩家):
public class PlayerMovement : MonoBehaviour
{
Rigidbody rb;
public float speed;
void Start()
{
rb = GetComponent<Rigidbody>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
rb.velocity = transform.forward * Input.GetAxis("Vertical") * speed + transform.right * Input.GetAxis("Horizontal") * speed;
transform.Rotate(0, Input.GetAxis("Mouse X"), 0);
}
}
I found an extremely simple movement script, that works in Unity 3D. The only problem is that the player falls extremely slow (almost not). How can I fix this? It's like it's being slowed down by something, because other objects are falling at normal speed. changing project settings doesn't work either.
C# Code (assigned to player):
public class PlayerMovement : MonoBehaviour
{
Rigidbody rb;
public float speed;
void Start()
{
rb = GetComponent<Rigidbody>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
rb.velocity = transform.forward * Input.GetAxis("Vertical") * speed + transform.right * Input.GetAxis("Horizontal") * speed;
transform.Rotate(0, Input.GetAxis("Mouse X"), 0);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是因为您手动设置速度,并且这会覆盖物理引擎(重力)也设置速度。您可以通过仅通过玩家动作设置 X 速度并保留由重力生成的 Y 速度来解决此问题。
对于跳跃,您可以施加垂直力,因此重力也仍然起作用
I think it's because you are setting the velocity manually, and that overrides the physics engine (gravity) from also setting the velocity. You could fix it by only setting the X velocity by player action, and keep the Y velocity that is generated by gravity.
For jumping, you can apply a vertical force, so the gravity force will also still work