Change the Rotation X value without changing Y and Z
Hello guys, I need your help as I am becoming crazy!
I am developing a top-down game and I have a 3D particle that I am using as my sight/crosshair for the gun.
I would need to change the rotation value of X according to the aim of the character without changing the Y and Z axis.
So if my character is looking down it will be (180, 90, -90) and if it is looking right it will be (90, 90, -90) and so on.
I don't know why is becoming so difficult to archive it...
Thank you in advance!
Answer by epicpython · Aug 17, 2020 at 06:24 PM
Unity documentation on rotation: https://docs.unity3d.com/ScriptReference/Transform-rotation.html
If you are having issues, you can also edit the rigidbody so that it is only allowed to rotate on certain axes.
1.Make sure your object has a Rigidbody. You can add one by clicking Add Component -> Rigidbody. You DO NOT want a Rigidbody 2D because you are using a 3D object.
2.There is a little arrow by the word "Constraints". Click on it to expand the drop-down menu.
3.Under "Freeze Rotation", check "Y" and "Z"
4.Oh, also make sure you have gravity turned off or the gun will fall down. On the Rigidbody, Uncheck the box by "Use Gravity"
Hope this helps!
Your answer
Follow this Question
Related Questions
transform rotations overwriting eachother 1 Answer
RogueLike 2D (Tutorial) Rotation of Player 1 Answer
How do I remove ALL components from a gameObject? 3 Answers
How would I project a Gameobject onto the surface of another? 0 Answers
transform.rotation has a different value in different events 1 Answer