Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Root Motion having no effect

Discussion in '2D' started by unity_sK1q8SV-XwfM9g, Feb 6, 2023.

  1. unity_sK1q8SV-XwfM9g

    unity_sK1q8SV-XwfM9g

    Joined:
    Oct 17, 2020
    Posts:
    2
    Hello,
    Recently I've been attempting to move my enemy prefab using Root motion as I'd been finding that meshing static move animations with Rigidbody based movement in scripts comes out looking extremely awkward. And is tricky to time correctly.

    So I thought I'd give rootMotion a go as it seems an easy way to plot out how my enemy characters move about. However I've been struggling to get even a basic example working.

    Here is the animation in the animator with the root of the enemy hierarchy set to move from a default (0,0)
    position to a (-10,0) :


    This is on the prefab for my enemy character. However if I drop the character into my scene manually it doesn't move at all. Nor does it work with my spawning script that Initializes the prefab at predefined spawn locations in the scene.
    The animation is set as the Idle node so it should start immediately and I can see it playing in the animator window:
    AnimationInspect.PNG
    The animator
    Capture.PNG
    For now I've detached the rigidbody, all scripts and box colliders to simplify the scenario as much as is possible. But I'm having no luck getting the thing moving at all.
    Am I missing something fundamental? Is a positional change from (0,0) on the root of the gameobject to a different point on the prefab the correct way? I've searched around but most videos and threads seem to focus on 3d modelling and rigging for root motion which isn't relevant to my simple 2D scenario.

    Can provide any screen shots of the gameobject or world properties if needed.
    Thanks guys.
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    This video seems to list a few requirements I don't think you're meeting with regards to the rigging / avatar / animation.



    Interesting bits start a little after 2:30
     
    unity_sK1q8SV-XwfM9g likes this.
  3. unity_sK1q8SV-XwfM9g

    unity_sK1q8SV-XwfM9g

    Joined:
    Oct 17, 2020
    Posts:
    2
    Thanks for the reply.
    But this is what I meant in my initial post. The video seems to focus on rigging and bones and typing the asset over to the "humanoid". I don't have any of this(nor do I want or need it) as far as I know. Unless I'm mistaken?
    I'm dealing with a simple 2D sprite gameobject that I turned into a prefab. I'm simply trying to use the animator to control the movements of my enemy prefabs. I was led to believe root motion was the key to this. But everyone seems to be using it for complex 3d bone based characters or assets imported from 3D modelling suites. Which is worlds away from what I need(I think).
    The only video I could find that even uses a simple Unity 2d gameobject is the following:

    But the video is extremely outdated and there isn't a "generate motion curves" button. Im assuming it was removed at some point because its not needed but in any case his simple example doesn't work for me and my gameobject remains static.
    Id love for someone to show me a simple root motion example working in a 2D context if that were possible.
    Again thanks for the reply friend!