- Home /
How to hold a child objects position relative to parent as it moves.
I have a particle emitter that I need to planted, always 10 units from camera on z plane, as the camera spins and moves. I want to emitter to stay x = 0, y = 0, z = -10 units from my camera and always face the camera to send particles it's way.
The camera can move around in space and spin 360, if the camera spins 180 it will be facing the emitter rather than the emitter spinning around as a child object would behave.
Answer by Novodantis 1 · Jun 12, 2010 at 08:32 AM
I'm not sure I understand this correctly, but if you parent the emitter to the camera it should stay in the same position relative to the view, that happens automatically.
If you want the emitter object to follow the camera's position but not it's orientation, attach to it a Follow script (note; object must be unparented for this to work properly):
var offset : Vector3; var targetObject : Transform;
function Update() { transform.position = targetObject.position + offset; }
Where targetObject is set to the camera and offset is the desired local coordinate of this emitter. You can make this script much more automatic and clever of course; it's just a start point.
Your answer
Follow this Question
Related Questions
Where to find original unity Parent/Child script? 2 Answers
Find Child's Position Relative To World (Global Position) 1 Answer
Make a simple tree 1 Answer
Add force to Child while it's parent rotate around something..... 0 Answers
Find position of the GameObject this script is attached to. 2 Answers