Position not updating once animation has played

So this has been nagging me for a while and its probably a simple fix, but I have no idea how to do it. So what’s happening is I set the position in my animation tab then play the animation when a certain key is pressed and update the position of the player. I have even tried to set the cube as a child of an empty parent object (maybe I’m doing it wrong), a video may be of help :smile:

Scene view

This is the script (written in C#):

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

//Uses animations based on input and if no key is pushed then you stay idle
void Update() {

if(Input.GetKey(“w”))
{
animation.Play(“CubeMovementForward”);
}
else if(Input.GetKey(“a”))
{
animation.Play(“CubeMovementLeft”);
}
else if(Input.GetKey(“s”))
{
animation.Play(“CubeMovementBackward”);
}
else if(Input.GetKey(“d”))
{
animation.Play(“CubeMovementRight”);
}
else if(Input.GetButtonDown(“Jump”))
{
animation.Play(“CubeMovementJump”);
}
}
}

(The position set is the same start position for all levels)

And a video to show

I haven’t used Mecanim yet but this is the issue you would encounter with the legacy animation system. It is probably the same.

An animation doesn’t Actually update the position. What you want to do is have an animation ‘in-place’ and move it programmatically. Or move it programmatically when the animation is done (using transform.position). Thought it looks like it’s moving, the block’s Pivot hasn’t changed. So when the animation is done, it’s just going to go back to idle.

Do you have a quick edit for my current script to help make this change?