Search Unity

Parenting camera problem

Discussion in 'Scripting' started by angel_m, Aug 21, 2009.

  1. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    I have a "smooth follow" type of camera like a child of my vehicle (car) gameobject. (I need that setup). The case is: like the car is the parent of the camera , the camera plays like fixed to the back of the car and the supossed smooth rotations from the smooth-follow script don't work.
    I have tried writing "transform.parent=null" just before all the rotation-position code in the smooth-follow script and, just after that, I use "transform.parent = car" but it has not any effect on the rotations, I mean, the camera continue like parented and fixed to the car gameobject. :(

    I want to get the smooth rotations from the smooth-follow script for the camera, but, at the same time, I need the camera to be parented to the car gameobject. Any idea?
    Thanks in advance.
     
  2. calveit

    calveit

    Joined:
    Jul 4, 2009
    Posts:
    42
    You can try to manipulate the camera in local space, rather than world space.

    Try using transform.localRotation and transform.localPosition in your camera behaviour script.
     
  3. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Thanks Calveit but the problem was easier solved introducing a "yield" instruction before the rotation-position (for the camera) part of the code. :)