【发布时间】:2021-02-12 09:55:59
【问题描述】:
我正在创建一个游戏,其中我将成为一个立方体。但是当我在 X 轴上移动我的立方体时,Z 轴会发生变化。 我还阻止了 X、Y、Z 旋转。
我的代码:
using UnityEngine;
using System.Collections;
public class CubeControl : MonoBehaviour {
private Vector3 input;
void Update () {
if(Input.GetKey(KeyCode.D)){
input = new Vector3(25, 0, 0);
rigidbody.AddForce(input);
}
if(Input.GetKey(KeyCode.A)){
input = new Vector3(-25, 0, 0);
rigidbody.AddForce(input);
}
if(Input.GetKey(KeyCode.W)){
input = new Vector3(0, 0, 25);
rigidbody.AddForce(input);
}
if(Input.GetKey(KeyCode.S)){
input = new Vector3(0, 0, -25);
rigidbody.AddForce(input);
}
}
}
【问题讨论】:
-
嘿,分享你的立方体检查器值的快照。此外,最好使用 FixedUpdate 而不是 Update 方法,因为您正在尝试施加恒定的力。
-
@Billatron i.imgur.com/r7LFbi8.png
-
很可能是重力下降的原因。
-
Sooo...我该怎么办?
-
你改变重力方向了吗?通常它影响到 -Y 方向,而不是 Z 轴。