U
U
Uncle Bogdan2021-02-06 14:49:30
C++ / C#
Uncle Bogdan, 2021-02-06 14:49:30

The player rotates by the initial degree when the joystick is released. How to fix?

Made controls using the Joystick Pack asset. The video shows that when you release the joystick, the character turns sharply.
https://youtu.be/yLC8NPjxJ_E

private void FixedUpdate()
    {
            MoveAndroid();
            LookAtAndroid();
    }

    private void MoveAndroid()
    {
        MoveVelosity = new Vector2(joystick_Move.Horizontal, joystick_Move.Vertical).normalized * Speed;
        Body.velocity = MoveVelosity * Time.fixedDeltaTime;
        LookAtAndroid();
    }
    public void LookAtAndroid()
    {

        float Angle = Mathf.Atan2(joystick_Move.Vertical, joystick_Move.Horizontal) * Mathf.Rad2Deg;
        Quaternion OldRotation = transform.rotation;
        transform.eulerAngles = new Vector3(0, 0, Angle);


        if (Joystick_Attack.transform.Find("Handle").localPosition != new Vector3(0, 0, 0))
        {
            Angle = Mathf.Atan2(Joystick_Attack.Vertical, Joystick_Attack.Horizontal) * Mathf.Rad2Deg;
            Joystick_Attack.
            transform.eulerAngles = new Vector3(0, 0, Angle);
        }
        
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question