为什么在字符控制器中不移动我的播放器中的移动功能?

发布于 2025-02-12 06:23:40 字数 1234 浏览 1 评论 0原文

因此,我有一个带有字符控制器的播放器模型,并且要管理播放器移动,我以下文件:

using UnityEngine;

public class CharacterMovementController : MonoBehaviour {
    Animator characterAnimator;
    CharacterController character;
    [SerializeField] Transform mainCamera;
    [SerializeField] float sprintBoost = 10f;
    [SerializeField] float currentSpeed = 20f;
    [SerializeField] float trueSpeed;
    // Start is called before the first frame update
    void Start() {
        characterAnimator = gameObject.GetComponent<Animator>();
        character = gameObject.GetComponent<CharacterController>();
    }

    void Update() {
        // There was a bunch of animation stuff that I figured wouldn't be important for
        // you to read

        Vector3 move = new Vector3(Input.GetAxis("Horizontal") * trueSpeed, 0, Input.GetAxis("Vertical") * trueSpeed);
        // Movement Logic
        character.Move(move * Time.deltaTime);
    }
}

< img src =“ https://i.sstatic.net/pogqq.png” alt =“组件“>

我已经试图将玩家的Currentspeed拖到疯狂的数字上,但仍然没有任何作用。我检查了字符控制器正在正确引用,并且移动函数正在vector3对象中传递

So I have a player model with a character controller attached and to manage the player movement I have this file below:

using UnityEngine;

public class CharacterMovementController : MonoBehaviour {
    Animator characterAnimator;
    CharacterController character;
    [SerializeField] Transform mainCamera;
    [SerializeField] float sprintBoost = 10f;
    [SerializeField] float currentSpeed = 20f;
    [SerializeField] float trueSpeed;
    // Start is called before the first frame update
    void Start() {
        characterAnimator = gameObject.GetComponent<Animator>();
        character = gameObject.GetComponent<CharacterController>();
    }

    void Update() {
        // There was a bunch of animation stuff that I figured wouldn't be important for
        // you to read

        Vector3 move = new Vector3(Input.GetAxis("Horizontal") * trueSpeed, 0, Input.GetAxis("Vertical") * trueSpeed);
        // Movement Logic
        character.Move(move * Time.deltaTime);
    }
}

Screenshot of the component

I already tried to drag the currentSpeed of the player to insane numbers and still nothing works. I checked that the character controller is properly being referenced and the Move function is being passed in a Vector3 object

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小苏打饼 2025-02-19 06:23:41

因此,显然这一切都是关于阶跃偏移的,我有一个大型型号,我必须缩小很多尺寸

So apparently it was all about the Step offset, I had a large model which I had to scale down a lot meaning the offset had to be suer low, in the end I made it 0.01

听风吹 2025-02-19 06:23:41

请勿将输入值(input.getAxis(“ Horizo​​ntal”)input.getAxis(“ vertical”))与移动字段,将其与总体向量相乘:

Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
// Movement Logic
character.Move(move * Time.deltaTime * trueSpeed);

请参阅 pronage> prinatecontroller.move

Do not multiply the input value (Input.GetAxis("Horizontal") or Input.GetAxis("Vertical")) with the speed in the move field, multiply it with the overall vector instead:

Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
// Movement Logic
character.Move(move * Time.deltaTime * trueSpeed);

Refer to the CharacterController.Move documentation for more info

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文