A
A
ALTech12020-05-10 12:10:22
Unity
ALTech1, 2020-05-10 12:10:22

How to fix a bug with player movement?

5eb7c4a78d92d443442992.png
When I don't move the joystick, the arrow points down. When I move the joystick everything is fine, but as soon as I let go it immediately sticks to the ground. Help how to fix it? Maybe something is wrong with the model export?

Script:

public float speedMove;
    public float gravityForce;
    private Vector3 moveVector;
    Vector3 direct;
    private Jostic joystick;
    void Start()
    {
        joystick = GameObject.FindGameObjectWithTag("Joystick").GetComponent<Jostic>();
    }

    // Update is called once per frame
    void Update()
    {
        transform.rotation = Quaternion.LookRotation(direct);
        CharterMove();
    }
    private void CharterMove()
    {
        moveVector = Vector3.zero;
        moveVector.x = -joystick.Vertical() * speedMove;
        moveVector.z = -joystick.Horizontal() * speedMove;
        moveVector.y = gravityForce;

        if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) < 0.0f)
        {
             direct = Vector3.RotateTowards(transform.forward, -moveVector, speedMove, 0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }
        else transform.rotation = Quaternion.LookRotation(direct);


        GetComponent<CharacterController>().Move(moveVector * Time.deltaTime);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DanielMcRon, 2020-05-10
@ALTech1

Assignment of gravity?


moveVector.y = gravityForce;

Maybe so?
moveVector.y -= gravityForce;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question