Search Unity

Trying to use parent/child combo to rotate an animation in Unity 2D

Discussion in 'Scripting' started by johnjackperry, May 9, 2021.

  1. johnjackperry

    johnjackperry

    Joined:
    Feb 14, 2021
    Posts:
    2
    I have an animation that I'd like to use on a prefab projectile. Right now I've set the projectile to transform its z rotation in the direction it's moving in c#, but I've been unable to apply both the changes in rotation and animation at the same.
    • I've tried the common solution of moving the animator onto a child, keeping the rigidbody, script, and collider on the original parent object - but the animation is not responding to the rotation of the parent.
    • I've also tried moving the rotation commands to late update (didn't work).

    • I've also heard of some people using a combination of stuff in C# instead of making a child object:
      animator.enabled = false;
      animator.enabled = true;
      and
      animator.Play();

      but I'm pretty new the animator and don't really understand the details of how I could use this (I think this would be a better solution than making a child object just for the animation)
    See attached images for my code and inspector/game settings. Am I missing something? Do I need to put the animation commands in a separate script on the child object?

    Screen Shot 2021-05-09 at 1.18.14 PM.png Screen Shot 2021-05-09 at 1.33.27 PM.png Screen Shot 2021-05-09 at 1.34.10 PM.png
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Everything should work just fine as a parent-child setup, with the animation on the child and the world movement on the parent. Strip it down to basics and make sure everything is working individually. Can you make just the child animate by itself? You're also starting a new IdleCheck() coroutine every single frame that your first if condition is true, could that be the issue?