Objects movement

PG: https://www.babylonjs-playground.com/#LL5BIQ#276

I want to make this little man run realistically (that is, change its coordinates and move on the plane). How can i do this?

You can try something like this:


I need the motion to obey the laws of physics. At the moment, I created a physical box around the man and I set it linear speed, but it seems to me there is a more correct way

Sorry, I know nothing about physic engines, I think someone else will have to comment about this.

Adding @Cedric, to see if he can lend his expertise to this one.

The root motion velocity is (almost) never linear. That means that if you find an estimation or an average speed of the root motion, you’ll get sliding feet.
If you want a more realistic motion, you have to compute the root speed (delta vector of root position / frame duration) per frame. And at scene update time, compute the new root position which is (previous root position + speed(frame) * frame duration).
That being said, the root in the PG doesn’t seem to move, at least in the direction of the motion. So, I’m not sure it’s possible to do it with this animation.
There might be another way to estimate the root speed. If you can compute the feet stance time and assume the feet don’t move when on the ground then the derivative distance between the ankle and the root can be the root motion speed.
This is also an issue when running because you may have no stance for some part of the animation.
Do you have an animation with a root that moves?

I was working on a physics character controller at one point if any of this helps
You will need a USB Controller hooked up to interact right now though. (maybe even has to be a dualshock Im not sure)

PG: https://www.babylonjs-playground.com/#LL5BIQ#280

I have one more question, I hope you can help :slight_smile:
How can I rotate a man depending on the direction of the linear velocity vector?

PG: https://www.babylonjs-playground.com/#LL5BIQ#295

const getDeg = (x, z) => {
    const degInit = Math.PI / 2 - Math.atan(Math.abs(z) / Math.abs(x));

    if (z < 0 && x > 0) {
        return Math.PI - degInit
    } else if (z < 0 && x < 0) {
        return (Math.PI + Math.PI / 2) - degInit;
    } else if (z > 0 && x < 0) {
        return -degInit;

    return degInit;

I wrote a function that calculates the required rotation angle depending on the velocity vector

x and z are the values ​​of the vectors

PG: https://www.babylonjs-playground.com/#5THKLY

To my mind I got what I wanted! :slight_smile: