我的播放器预制件可以向前移动,直到碰到一个物体,这是怎么回事?

问题描述 投票:0回答:1

我正在基于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);
        }
    }
}

如果您能找到解决此问题的方法,请告诉我。

c# unity3d 3d camera move
1个回答
0
投票

您可以通过跟踪并在FixedUpdate中对其进行严格设置,将其固定在Y方向上。

© www.soinside.com 2019 - 2024. All rights reserved.