Search Unity

Alter animation values for 2 Joy control

Discussion in 'Scripting' started by Benmaster, Dec 3, 2019.

  1. Benmaster

    Benmaster

    Joined:
    Aug 11, 2016
    Posts:
    39
    Currently im working in a RPG like game to use with gamepads, to make the character moving I have 2 ways:

    1 Joy: you move with left Joy, and the rotation is changed automaticly using this:

    float moveHorizontal = GamePad.GetAxis(GamePad.Axis.LeftStick, GamePad.Index.Any).y;
    float moveVertical = GamePad.GetAxis(GamePad.Axis.LeftStick, GamePad.Index.Any).x;
    transform.eulerAngles = new Vector3(0, Mathf.Atan2(moveHorizontal , -moveVertical ) * 180 / Mathf.PI, 0);

    2 Joy: you rotate the player with Right Joy and then move with Left, to aim without move the character.

    My issue come now with the animator, because I have a 2D BlendTree, and based on moveHorizontal and moveVertical I put the correct animations, but in the 2 Joy setup, I dont figure how to "substract" the angle from the Right Joy in the Left Joy to send to the animator altered values based on the Right Joy rotation.

    any idea?