Search Unity

Resolved How to rotate an object clockwise and anti-clockwise with different animations in script ?

Discussion in 'Scripting' started by Siyka, Mar 20, 2023.

  1. Siyka

    Siyka

    Joined:
    Aug 17, 2014
    Posts:
    10
    Hello,
    I would like to move player with on-screen joystick (3D project with New Input System) and have 4 animations for run - run with left leg and run with the right leg for forward and other 2 animations (circle left and right) for running with rotation left and rotation right.
    I need help with Player direction - clockwise for right and anti-clockwise for left leg.
    direction = Mathf.Atan2(stateMachine.InputReader.MoveComposite.y, stateMachine.InputReader.MoveComposite.x) * Mathf.Rad2Deg;
    work fine only on joystick vertical axis positive.
    I tried other idea:
    deltaY = (stateMachine.InputReader.transform.rotation.y - prevRotation.y) * Mathf.Rad2Deg;
    where
    private Quaternion prevRotation = Quaternion.identity;
    without success too. Object has to rotate to the left always with the left leg and to the right with right leg.
    If possible, please help.
     
  2. Siyka

    Siyka

    Joined:
    Aug 17, 2014
    Posts:
    10
    Problem solved. Thank you so much!
     
    orionsyndrome likes this.
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    You're welcome! Come again :)