我正在基于TierZoo制作一个统一游戏,并且在测试运动脚本时,我撞进了其中一棵刚体树以求娱乐……这使玩家的预制件停止前进,并且开始奇怪地运动指示这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewPlayerController : MonoBehaviour
{
private Rigidbody rb;
public GameObject player;
public float thrust = 1.0f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W))
{
rb.AddRelativeForce(player.transform.right * thrust * 2.5f);
}
if (Input.GetKey(KeyCode.A)) { player.transform.Rotate(0, -1, 0); }
if (Input.GetKey(KeyCode.D)) { player.transform.Rotate(0, 1, 0); }
if (Input.GetKey(KeyCode.S))
{
rb.AddRelativeForce(player.transform.right * thrust * -2.5f);
}
}
}
如果您能找到解决此问题的方法,请告诉我。
您可以通过跟踪并在FixedUpdate
中对其进行严格设置,将其固定在Y方向上。