Search Unity

Question turning 90 degrees to the current position.

Discussion in 'Scripting' started by WirealTalha, Sep 15, 2020.

  1. WirealTalha

    WirealTalha

    Joined:
    Jul 19, 2018
    Posts:
    142
    Hi, Imagine a 2D character moving in a straight line( any direction, literally any). For movement I have attached a rigidbody to the Gameobject and set the state from dynamic to kinematic.

    When I press the mouse button I want to turn the character 90 degrees (keeping the motion of the character intact).

    How can I achieve that?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    You can use Transform.Rotate() on the instance of the Transform you want to turn.
     
  3. WirealTalha

    WirealTalha

    Joined:
    Jul 19, 2018
    Posts:
    142
    Thankyou For your reply, Can you help me out with this-->

    How to rotate/turn the face of my 2d object in the direction of motion of my 2d object. My 2d object is moving in straight lines, and it turns at an angle of 90 degrees.