Search Unity

How to script an animation/animator to stop mid animation, toggle play direction

Discussion in 'Animation' started by madmanrex, Jul 27, 2018.

  1. madmanrex

    madmanrex

    Joined:
    Jul 15, 2013
    Posts:
    18
    and potentially transition change object on raycast hit?

    Hello everyone

    I am not sure if this is an animation question or a scripting question. Primarily it is animation I assume but anyway. I am hoping to get some insight from the lovely people of this community on how to get an animation or animators to get the desired effect I am looking for.

    I am trying to work on my final major project for university and was trying to make it so that the player can shoot certain objects in the environment with an ageing ray. I thought that the best way to do this effect is by having an animation attached to the objects that need to change and trigger them with a raycast.

    It would age them in one direction when first hit but then back in the other when hit again. It would be a ray that would need to be kept held down to complete the transition from old to new or new to old or at least have it complete it's animation first before going in the opposite direction.

    Sorry if this just sounds like me asking for someone to script it for me but I mainly am hoping for guidance and maybe some example script work so that I can understand what I can do. I had given it a try myself looking into animations and animators getting as far as making it run the animations but couldn't get it to stop and start from the current frame that it was left on or get it to go in reverse.

    Any help with this would be much appreciated.

    The pictures below are the difference between my first and last frame of the test animation that I am trying to get working so that I can apply the code or method to others later. Hopefully being that simple but I know it never is.

    upload_2018-7-27_15-4-43.png
    upload_2018-7-27_15-5-2.png
     
  2. TantzyGames

    TantzyGames

    Joined:
    Jul 27, 2016
    Posts:
    51
    If you have young and old values that are the same for every object, it may be easier to do it all in a script using "lerp". A bool deciding which direction it's going.

    Otherwise with an animator, you just need a clip going from young to old. Using speed, you can play forwards or backwards or pause.