Do action according to linear velocity of physics object

Hi!

This should be an easy answer. (keyword: should)

For my current project, I would like to do an action depending on the Linear Velocity of an object. I am using var howfast = object.physicsImpostor.getLinearVelocity(); console.log(howfast); so I can see how fast it is going.

Is there any way to use an if-else statement with the variable howfast? Like if (howfast > 9001) console.log("It's over nine thousand!");:wink: Pardon the dead meme.

Thanks for any help!

Givo

I think you mostly answered your own question? getLinearVelocity returns a Vector3, so maybe you are actually asking how to go from a Vector3 to a number? If so, Vector3.length might be the answer you are looking for?

Or, perhaps you were wondering how to do this check all the time? If that is the case you could try the registerBeforePhysicsStep

I recommend reading the docs for the tools you are using to see what all is possible.

Thanks for the response! Vector3.length might work, as I’m detecting the X and Y values of an object.

I’ll try it out!

Givo

I just tried .length, so console.log(howfast.length); and got this
38%20PM
what’s up with that?

You console logged the code for the .length function. Do console.log(howfast.length()) (functions require the () )

2 Likes

I realized that.:upside_down_face:

Thanks for the help.

I’m piecing stuff together right now. I’ll post again if i need any more help.