- Home /
Parent and child repositioning
I have a ladder climbing animation where I tried scripting the player to be placed on the upper platform while the animation takes place at the bottom of the ladder. Everything works fine, except that when the animation is executed in-game, you can see the player's sprite going up and back down quite quickly.
I've tried countless things like: Using an animation event at the beginning of the animation
Repositioning parent and child when the Animator is playing the ladder climbing animation "if(anim.GetCurrentAnimationState(0).IsName("LadderClimb"))"
Having it wait until the end of the frame and then repositioning both. "yield return new WaitForEndOfFrame()"
I can't move the child gameobjects in-game using the movement arrows except when I disable the Animator component, which obviously makes me think that it has to do with the Animator. Any help with this would be hugely appreciated.
The player is being parented? Don't think you should have to do that. This animation shouldn't be a problem. Seems like a code problem, but can't help you without seeing the code.
The player isn't parented, the player's arms, legs, torso and head are parented to an empty Gameobject as a "vessel" of sorts. I animate the body parts within the vessel. The vessel itself is parented to another empty Gameobject, so that I can move the player's entire body in one go when animating. That way the changed position remains a local position ins$$anonymous$$d of a world position, which makes animations reusable.
![alt text][1] [1]: /storage/temp/45058-player-children.jpg
I've already fixed it, but I find the fix quite inelegant. I've made a sprite of the animation's first frame placed it at the bottom of the ladder and had it activated when the player gets repositioned and have the vessel deactivated and when the animation starts reactivate the vessel and deactivate that sprite's gameobject.
I'd still like to find a proper fix to this, if there is one.
Here's the relevant bits of code, unless you need to look at the whole the script:
if(transform.position.x == targetPos.x){
init$$anonymous$$ove = false;
anim.SetBool("$$anonymous$$oving", false);
if(doubleClicked){
climbing = true;
facingRight = true;
anim.SetTrigger("Ladder");
transform.position = new Vector3(1, 6.92f, 0);
vessel.SetActive(false);
climbFix.SetActive(true);
doubleClicked = false;
}
}
if(anim.GetCurrentAnimatorStateInfo(0).IsName("LadderClimb")){
vessel.SetActive(true);
climbFix.SetActive(false);
}
Your answer
Follow this Question
Related Questions
Should we check animation condition in Update or FixedUpdatE? 3 Answers
2D Animation does not start 1 Answer
Best way to - Animation Sync - Multiple gameObjects. 0 Answers
2 Different animations with 2 different update modes? 0 Answers
Unity showing "animator" component instead of the "animation" component 2 Answers