- Home /
How to prevent affect of parents rotation on child
Hi, I searched similar questions and most of them gave this piece of code for answer :
Quaternion rotation;
void Awake()
{
rotation = transform.rotation;
}
void LateUpdate()
{
transform.rotation = rotation;
}
But its not my answer. My problem is; I want to remove rotation affect which is provided by parent. So any other object or function can change transforms rotation.
Edit: (My Scenerio) :
In my game I used camera path and camera moves on a path while moving an object(vehicle) must follow the camera but only positional followign i dont want to rotate vehicle with camera.
Why are you parenting objects if you don't want to move/rotate them together? It seems you would be better off parenting your children to another object that just moves along with the ex-parent.
I couldn't explain my question nicely so I edited my question.
Answer by dsada · Jul 21, 2014 at 11:20 AM
Instead of parenting the camera try to create a script that moving them just as the camera moves.
public class CameraFollow : MonoBehaviour
{
public Camera camera //assign the camera in inspector or in Start()
private Vector3 prevPos;
void Start()
{
prevPos = camera.transform.position;
}
void Update()
{
Vector3 displacement = camera.transform.position - prevPos;
prevPos = camera.transform.position;
this.transform.positon += displacement;
}
}
and put this script on the object you would like to keep the distance from camera
I tried that before it works but this time they were not updating same time and because of that reason vehicle vibrating and we cant get smooth vision. I Solved this question by using duplicated camera path. Thanks anyway.
There is a script in the standard asset folder which you can import to do the job. I think it was called 'mouseorbit' without quotes. Let me know if that's what you're looking for or if it works for you.
Answer by haim96 · Jul 21, 2014 at 01:51 PM
use a script like suggested but put the camera movment in Lateupadet() instead of updtae(). that should do the trick...
I tried but problem is same but as I said I solved by using duplicated camera path. Thanks.
Your answer
Follow this Question
Related Questions
Why is a child object not rotating properly with parent? 1 Answer
Why do grouped Terrain objects move together but don't rotate as one? 1 Answer
Simple Script Problem 1 Answer
children doesn't take parent's rotation, position or scale. 1 Answer
Having difficulty with Parent Object rotation and Child Object movement. 0 Answers