Confused with the animations

I’ve seen a lot of tutorials on how to do unity animations. If you put keys along the transform property, Unity will record the animation in world space.

When you play the animation, it will ignore the current position of your object and it will switch back to the world position where the animation was recorded.

This problem can be solved if you parent the animated model to an empty gameobject. From then on, your animated model will move relatively to the parent.

Now, lets say that I’ve added a smooth animation which moves my object 2 units along the X axis. I’ve parented this model to an empty gameobject.

I’ve added just 2 keyframes, one at time 0 with transfrom.position at (0, 0, 0) and one at the ending time with transform.position at (2, 0, 0).

Everytime I hit a button I want my animation to play. When my animation plays, it animates correctly the 1st time, but the 2nd time the position resets to the (0, 0, 0) and goes to (2, 0, 0) again! I would like it to go to (4, 0, 0) the 2nd time.

If I had moved the parent along with the child to the new position, then the child would have moved 4 units along the X axis the 2nd time of the animation (in total, if you sum up the 1st and the 2nd animation).

So, what is the solution to my problem? Should I move the parent object along with the child? Should the parent play the animation, and, if I record the animation for the parent object, shouldn’t it have a parent itself so as to avoid the world to local space problem?

I posted this at Unity Answers as well, but I didn’t get any responses. I hope I was understandable.

don’t set loop.

Edit:
Clamp forever is what your looking for.
However it seems to not be working.

Source: Unity - Scripting API: WrapMode.ClampForever

The wrap mode has been set to Once, as it should!

How is Clamp Forever going to work? It doesn’t even seem related to my problem.

The problem is that the animation causes the plane to reset the position each time, while what I want is to add up to the current position, and not to reset it to (0, 0, 0) each time.

The same problem applies to the rotation of the animation as well. For example, if you have made an animation with 2 keyframes, one at the beginning with rotation (0, 0, 0) and another one at the end with rotation (0, 0, -90), you have a problem.

If the current rotation of your object is (0, 0, 0) it will successfully go to (0, 0, -90). The 2nd time (and each one after that) though, it will reset the rotation to (0, 0, 0) and then go again to (0, 0, -90).

I made a simple video demonstrating the problem:

BUMP!

This seems way too simple for not getting an answer…

BUMP!

What is the general way of making animations like this one? It’s a simple rotating plane. How to rotate it based on current rotation?

Desperate bump!

I solved the problem by making 4 different animations (depending on the current rotation 0, -90, -180, -270), but this is not the way to go, for sure!