- Home /
Object rotation as a children of the main camera
Hello,
I have a problem with the rotation of an object (simple arrow for the minimap). The object is attached to the camera as a children, so it takes the movement and the rotation from there. What i would like to do, is to make the object stop rotating up and down only left and right.(I tried with Rigidbody freeze rotation on X, but it`s not working) I would attache the arrow as a children to the FPSController, but I`m using Cinemachine in this scene so I need to attache to the main camera. thank you for your answers in advance! Have a nice day, Tamas
Answer by highpockets · Jun 20, 2019 at 10:39 AM
You could just point in the same direction constrained to the plane you want via Vector3.ProjectOnPlane().
Vector3 direction = Vector3.ProjectOnPlane(Camera.main.transform.forward, Vector3.up);
Quaternion rot = Quaternion.LookRotation(direction, Vector3.up);
@highpockets thank you for your answer, I put this lines of code in a script on the object, but unfortunately this changes nothing.
@unity_PfHgO2CCqrgBHA are you passing the rotation to the arrow object?
Probably best you upload your script
I have a dolly track in my scene, a vcam witch is following the track (it`s a simple walkthrough) and I have a $$anonymous$$inimap to show the user where is he exactly in the apartment. you can look around using the mouse, but can`t control the movement of the character. what i want is to rotate the arrow as you look around (if you look at the door the arrow must face to the door) right now works fine, when i move my mouse to the right the arrow turns right, if look to the left, turns left, but the problem is when i look up, or down the arrow follows the camera, and i don`t need that . I hope that this way is more understandable, I`m quite new in unity without any program$$anonymous$$g background, so I don`t know where to put your question, sorry
Your answer
Follow this Question
Related Questions
Instantiate GameObject to specific position on the Parent 2 Answers
Rotation Complications + rotation with parents and children? 1 Answer
Is it possible to rotate a child object regardless of the parent rotation ? 1 Answer
How to fix the rotation and Orientation in an object as a Children ? 1 Answer