Jump to content

Root motion for character animations?


Go to solution Solved by SpiderPig,

Recommended Posts

I've come from the Discord, and no one seemed to know what I was referring to. I looked through the documentation, and turned up with nothing, so I figured I'd ask here. Does Ultra support Root motion natively, or would that have to be programmed in? The game I want to make relies heavily on moving characters fast and in complex patterns, so programming the motion in manually is essentially impossible, or at least improbable.

  • Upvote 1
Link to comment
Share on other sites

If you can export this motion to glTF or FBX then it should work fine in Ultra. If you upload your model we can try it and show you the result.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Solution

Thought I'd add to this here.  I got it working but not very well.

This is the component that made it work.

class Rabbit : public Component {
private:
    shared_ptr<Entity> controller = nullptr;
    shared_ptr<Entity> pivot = nullptr;
    Vec3 root_start_pos;

public:

    virtual void Start() {
        controller = CreateBox(GetEntity()->GetWorld(), 0.1f);
        controller->SetCollider(nullptr);
        controller->SetColor(1, 0, 0);

        pivot = CreateSphere(GetEntity()->GetWorld(), 0.05f);
        pivot->SetParent(controller);
        pivot->SetColor(0, 1, 0);

        GetEntity()->SetParent(pivot);

        controller->Move(0, 0.05, 0);

        auto model = GetEntity()->As<Model>();
        if (model != nullptr) {
            auto root = model->skeleton->FindBone("Root");
            root_start_pos = root->GetPosition();
        }
    }

    shared_ptr<Entity> GetPivot() {
        return pivot;
    }

    Vec3 last_pos;
    int i = 0;
    virtual void Update() {
        auto model = GetEntity()->As<Model>();
        if (model != nullptr) {
            auto root = model->skeleton->FindBone("Root");
            
            auto local_pos = root->GetPosition();
            auto looped = false;
            if (local_pos.DistanceToPoint(root_start_pos) < 0.03f) {
                looped = true;
                Print("Looped" + WString(i));
                i++;
                last_pos = Vec3();
            }

            auto move_vec = local_pos - last_pos;
            last_pos = local_pos;
            controller->Move(move_vec);
            root->SetPosition(0, 0, 0);
        }
    }
};

In order for it to work I need to know when the animation begins again.

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...