问题描述
我正在 Unity 中制作游戏,但是对象旋转出现问题:我的坐标被冻结,但移动对象后它仍然旋转:
在视频中,我移动了对象,当我释放所有键时,尽管有冻结选项,它仍会旋转。
这是我的运动脚本:
public class Movement : MonoBehavIoUr
{
public int speed;
public int turningForce;
private int jumpForce;
public int jumpForceMax;
public Rigidbody rb;
bool doJump;
void Start()
{
}
private void Update()
{
if (Input.GetKeyUp("space"))
{
doJump = true;
}
}
void FixedUpdate()
{
if (Input.GetKey("space") && IsOnGround)
{
if (jumpForce < jumpForceMax)
{
jumpForce += 50;
}
}
if (Input.GetKey("w") && IsOnGround)
{
rb.AddRelativeForce(speed * Time.deltaTime,0);
}
if (Input.GetKey("a"))
{
rb.AddTorque(new Vector3(0,-speed * Time.deltaTime,0));
}
if (Input.GetKey("d"))
{
rb.AddTorque(new Vector3(0,speed * Time.deltaTime,0));
}
if (doJump)
{
rb.AddForce(0,jumpForce,0);
doJump = false;
jumpForce = 0;
}
}
private bool m_IsOnGround;
public bool IsOnGround
{
get
{
if (m_IsOnGround)
{
m_IsOnGround = false;
return true;
}
else
{
return false;
}
}
}
void OnCollisionStay()
{
m_IsOnGround = true;
}
}
如您所见,没有变换位置更改,并且启用了冻结 Y 选项。
希望有人能帮助我了解正在发生的事情。