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

Time:07-02

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

CodePudding user response:

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

CodePudding user response:

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

  • Related