- Home /
AnimationClip in local coordinates
Good evening,
I have an animation clip I want to play in my OnTriggerEvent, in local coordinates. In this case its just a box thats supposed shake (at its position of collision) if it passes a collider.
I've created the clip as an asset in the editor, having it shake from -0.1 to 0.1. Very simple. But all such clips are in world coordinates, right? So when it hits the trigger, the box flies away to the origin and does its little +-0.1 shake.
So, my question is: can i set the clip to somehow be played in local coordinates?
I know I can do it by creating a curve from scratch within my script, and setting the "localPosition" property, so thats one way to do it. But it seems very natural to demand that the clip be played in local space, right?
I read something about clips having to be attached to a parent object, for the animation coordinates to follow the object around. But I realy don't want to create a dummy parent in this case...
Answer by Paulius-Liekis · Apr 24, 2012 at 01:52 PM
But all such clips are in world coordinates, right?
AnimationClips contains curves for each affected transform. Animation controls transform.localPosition/localRotation/localScale.
So in your case it controls localPosition of your box. As your box doesn't have any parent object, so in the end yourBox.transform.position is equal to yourBox.transform.localPosition.
To achieve what you want simply parent your box to an empty game object. Set position of the game object to where you want your box to be and animation your box just as you do now.
Indeed, if not parented the local coordinates ARE the world coordinates. Created a dummy parent, works fine. Thanks!