- Home /
Can't change the transform position after an animation.
I have a character unit on a grid. After performing an action, the unit isn't on the correct part of the tile, so I want to manually set it. I want to do something like so:
void Attack() {
unit.anim.SetTrigger("Attack");
}
public void ResetPosition() {
unit.transform.position = originalPosition;
print("Attack is over");
}
I'm using an animation event to call ResetPosition when the animation is over. I've taken out some of the logic so it's easier to understand. "Attack is over" is printing to the console. I've also tried to do different things (like to destroy the object) and other things work here, but I can't adjust the transform.position at all. I think the animation is preventing me from changing the animation.
FYI, after attacking the character goes back to an Idle animation.
Answer by hexagonius · Nov 25, 2018 at 09:57 AM
That's correct. You're using an animator that is always in a state unless stopped. If that state has keyframes altering the position it will constantly write them even though the animation seems over (stopped at the last frame). You could stop the animator from animating, or you transition into a state where the position is not part of the animation.
Thanks. I wasn't aware that an animation overrides transform changes in script.
Your answer