- Home /
How to stop rotation in x and y axis???
Im making a 2D game and don't want the obkects to rotate in the x and y axis's This is my movement code so far
transform.right = player.position - transform.position;
transform.position = Vector3.MoveTowards(transform.position, player.position , speed * Time.deltaTime);
Answer by wertyq · Apr 14, 2020 at 01:25 PM
Instead of transform.right, maybe use transform.position.x instead
Answer by Charlie010903 · Apr 15, 2020 at 04:43 PM
@wertyq Ahh there is a component called Rotation Constraint and you can stop it rotating on the x and y axis. However know my enemy will flip over which I do not want .
@Charlie010903 If your object has a Rigibody2d component, you can freeze its rotation inside the Inspector under Rigidbody2d>Constraints
Freeze Z axis and it should stop your enemy from flipping over
@wertyq But the game is 2D so I want it rotating in the z axis i dont want it rotating in the x and y axis
What did you actually mean by your enemy flipping over?
Your answer
Follow this Question
Related Questions
Rotate z and y together? 1 Answer
,The object rotates in z axis unwantedly 2 Answers
How do I make an angle with the X axis, Y axis, and Z axis and not rotate AROUND the axis? 0 Answers
Set rotation based on 2 points problem 1 Answer
Sprite rotation (z-axis) and translation (y) is not working 1 Answer