Answer the question
In order to leave comments, you need to log in
How can you change the rotation of an object in Unity3D?
Good evening. I would like to know how you can make the rotation of an object along the Y axis equal to the rotation along the Z axis of its parent.
Parent
└ Object
Answer the question
In order to leave comments, you need to log in
Call this code on a child object:
var ownLocalAngles = transform.localEulerAngles;
ownLocalAngles.y = transform.parent.eulerAngles.z;
transform.localEulerAngles = ownLocalAngles;
Look in this direction, I used this implementation on the head of the tank (the main condition was to rotate the head locally, according to the global camera coordinates), so that it would rotate correctly. The muzzle looks where the camera is looking, the rotation of the tank itself is taken into account. (here the interpolation is removed).
gun.localRotation = Quaternion.AngleAxis(_cacheCamera.eulerAngles.y - transform.eulerAngles.y, Vector3.up)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question