Search Unity

Question Stop root animations over-extending?

Discussion in 'Animation' started by TiggyFairy, Dec 8, 2022.

  1. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    506
    Hey, I've been having problems with one of my gates. Every time I open or shut it, the animation slightly over-extends on the way down so that when the gate comes back down it goes through the terrain. Play it too much, and you can't even go through because it doesn't rise or fall enough. I'm stumped here. I don't know how to stop this, or why it's happening. I've made and remade the animation four our five times with the same effect. It has happened in my other game too. I'm thinking of just using physics and a move script - but that may not always be possible. Here are all the details I can think to include:

    Root animation playing the same animation three times (for gameplay reasons), but even when you do it with one animation it's just more subtle. On the way down the animation is reversed with speed -1. I've tried multiple other settings, but nothing really totally fixes it. animation generated by recording. Doesn't matter if the model is a basic cube or my own custom mesh.

    Any ideas what this is?
     
  2. Billy123456789872222221

    Billy123456789872222221

    Joined:
    Jul 11, 2023
    Posts:
    3
    This isn't an answer, but I just wanted to say I'm having a similar problem. I'm trying to have randomly generated rooms with containers that have drawers that are also randomly generated. Of course, root motion is necessary because I don't want all the drawers to teleport to the position of the original drawer I animated, and so I applied root motion. However, for some reason, this caused the drawers to extend out way too much, and ruined the animation. I can't fix it by reanimating it because the animation doesn't want to take any changes while root motion is still enabled, and I suppose one way to fix it would be to have a script that constantly draws back the drawer if it goes over the maximum extension, but it just seems like there should an easier way of going about it.
     
    TiggyFairy likes this.
  3. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    506
    I recommend using tweens, if collision isn't an issue. Download DoTween from the asset store. Put the draw in a parent object that sits where you want it when closed. Use DoLocalMove and rotation to open it by sending it to the location you want. Then send it to Vector3.zero to close it.

    Or the reverse.

    Code (CSharp):
    1. transformOrRigidbody.DOLocalMove(new Vector3(2, 0, 0), 0.9f * Options.uiSpeed).SetEase(Ease.Flash);
    or

    Code (CSharp):
    1. transformOrRigidbody.DOLocalMove(new Vector3(2, 0, 0), 0.9f * Options.uiSpeed).SetEase(Ease.Flash);.onComplete = delegate ()
    2. {
    3.  
    4. ///Put something here that happens when the tween ends.
    5.  
    6. };
    NOTE: you can set the Ease to whatever style you want. The ease controls how the tween moves. If it's smooth. If it bounces. etc
     
    Last edited: Jul 22, 2023