Has anyone tried 2d rotation

Hey guys I’m making a game right now i wanted to ask if anyone here has tried 2d movement, that is rotating in the direction of movement in a 2d like manner in a more simple way other than Richard’s Delamore’s method, if you have can you please post your script here

That would be pretty simple, just create a int variable to store the direction you last pressed the key to go in and rotate your character towards that direction, using Vector3.Lerp or Quaternion.Slerp. The int variable will go from -1 (left) to +1 (right). You can also use value of the variable to affect the direction of your character’s movement. Then, this Vector3 can control direction:

Vector3 moveDirection = new Vector3(Vector3.Right * Speed * directionVariable);

As always I prefer code example

I gave you one. This is basically a one liner. The directionVariable can be changed using a couple if statements:

if (Input.GetAxis("Horizontal") > 0)
{
    directionVariable = 1;
    // Code to trigger actual mesh to rotate towards y=90
}
else if (Input.GetAxis("Horizontal") < 0)
{
    directionVariable = -1;
    // Code to trigger actual mesh to rotate towards y=-90
}

Then you can apply the moveDirection variable mentioned above to whatever method of motion you are using for your character actor.

Thank you so much, I really appreciate you

1 Like

It’s my pleasure! That’s why we’re here! :ok_hand: :grin:

1 Like