我为我的Player对象制作了这个脚本。它有儿童,1个相机和1个型号。 他们的问题是每当我移动鼠标时玩家向下移动。然后凸轮上升。
脚本:
public GameObject cam;
public float sensitivity = 2f;
public float walk_speed = 2f;
public float run_speed = 2f;
CharacterController player_CC;
float speed;
float moveFB;
float moveLR;
float rotX;
float rotY;
bool canMove;
void Start () {
canMove = true;
player_CC = GetComponent<CharacterController>();
speed = walk_speed;
}
void Update () {
if (canMove)
{
moveFB = Input.GetAxis("Vertical") * speed;
moveLR = Input.GetAxis("Horizontal") * speed;
rotX = Input.GetAxis("Mouse X") * sensitivity;
rotY = Input.GetAxis("Mouse Y") * sensitivity;
Vector3 movement = new Vector3(moveLR, 0, moveFB);
transform.Rotate(0, rotX, 0);
cam.transform.Rotate(rotY, 0, 0);
movement = transform.rotation * movement;
player_CC.Move(movement * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftShift))
{
speed = run_speed;
} else
{
speed = walk_speed;
}
}
答案 0 :(得分:2)
movement = transform.rotation * movement;
您将变换旋转乘以运动矢量。分开逻辑。
答案 1 :(得分:0)
我知道是什么造成的。但我不知道为什么会这样做。但我在同一个物体上使用了charachtercontroller和一个刚体。抱歉浪费你的时间:/