- Home /
In animations, is it possible to only add transform values instead of setting it?
Hello guys! There's a problem with an animation I made in Unity itself. I made a "bobbing" animation for my camera as the player walks but, it doesn't work as expected. It only plays the animation at the specific transform position values I put. What I'm trying to do is to add transform position values instead so that it gets to follow the player and doesn't get left behind. Is it possible? Or am I doing something wrong? Here is a picture of the problem in case you don't fully understand...
im not really sure im also having the same problem hope someone finds out!
Answer by Key_Less · May 09, 2014 at 05:27 PM
This is a pretty common issue. Your animation is effecting your camera's transform relative to it's global coordinates. In other words, it will always animate from the same spot relative to the world position of (0,0,0).
All you need to do is make the camera a child of an empty game object and set the camera's position to (0,0,0), this way it will always animate relative to it's parent's position. Then you can update the empty game object's transform to follow the player and your camera will move with it, while animating.
Alternatively, you could attach the camera to your player object, and offset the camera's position, in which case the camera will always follow the player. With this approach, you'd only need to worry about updating the player's position and the camera will inherit the changes. There is a simple example script of this on the Unity reference pages here.
Thanks for your help, I'll be trying it right now.
Sorry for the late answer accepting, was busy doing something else :p