简体   繁体   中英

Why isn't the Move function in Character Controller not moving my player?

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);
    }
}

组件截图

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

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

所以显然这都是关于步距偏移的,我有一个大模型,我必须缩小很多,这意味着偏移必须非常低,最后我把它设为 0.01

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM