[SOLVED] Calculate object speed?

Hello :wave:,

I have 3d object which has rigidbody and moves according to force.
I want to calculate speed of this object.

I tried this.entity.rigidbody.linearVelocity but it is not working as expected.

How I can calculate object speed?
Thanks in Advance :pray:

Hi @Ketan_ATA,

One common way to get the speed per frame (per physics simulation tick), is to use the length() property:

const speed = this.entity.rigidbody.linearVelocity.length();

That will give you the amount of space the object will traverse in the next simulation tick.

4 Likes

Hi @Leonidas :wave:,
This solution works perfect! :ok_hand:
Thank you very much @Leonidas for help! :pray:

1 Like

Is is possible to do the same with length() for an individual axis?

You can do that by taking the absolute value on any axis:

const speedX = Math.abs(this.entity.rigidbody.linearVelocity.x);
2 Likes