Sign in to follow this  
Bombadilo101

velocity/impulse

Recommended Posts

Is there some built in way to find the velocity of an object?  Was hoping to build in a maximum velocity and variable impulse for my spaceship game but was having trouble finding out whether or not an object was moving in space.

 

Currently using cannon.js for the physics engine.  Apparently if you use cannon with Three.js you can just do object.velocity.y or object.velocity.norm() but it doesn't seem to work in babylon.

Share this post


Link to post
Share on other sites

strange... seems there's no velocity check after all.  Not sure if they took it out or renamed it, but I ended up going with this:

 

  var zCheck = true
var veloZ = PC.absolutePosition.z;
  scene.registerBeforeRender(function(){
  if (Math.abs(PC.absolutePosition.z - veloZ) > 10)
  {
  zCheck = false
 }
 else {
 zCheck = true
 }
 veloZ = PC.absolutePosition.z
});
 
not pretty, but it seems to work.  I feel like there's got to be an easier way though.  What's a physics engine without a built in velocity checker.  Also I'm not certain whether renders are over a variable length of time or not so my checker could be seriously flawed.
 
just a z-axis check for the moment, still deciding whether to go with a 2-d or 3-d speedcheck in order to limit max impulse.

Share this post


Link to post
Share on other sites

Hi Bombadilo101, welcome to the forum.

 

http://www.babylonjs-playground.com/#1NMU7M

 

Watch your console.  Built-in velocity... in CannonJS.  Yay!

 

Like Raanan said, when you setPhysicsState on a mesh, a physics "body" is returned to you.  (line 27 - "sbody")

 

In line 30, I am printing the Y-axis velocity of sbody.... to console.

 

Here is the CannonJS API... for 'body'...  http://schteppe.github.io/cannon.js/docs/classes/Body.html

 

As for CannonJS unpredictable behavior,  I can't help you there.  I prefer using OimoJS, actually.

 

Below is the same thing in Oimo, but notice there is a change in line 30. Now it's sbody.body.linearVelocity.  And, I did some minor adjustments to the restitution (bounce) values.  And of course, line 8, switched to the Oimo plugin.  Notice the bounce is more predictable in OimoJS.

 

http://www.babylonjs-playground.com/#1NMU7M#1

 

OimoJS does not have a published API, but see http://urbanproductions.com/wingy/babylon/misc/j2h02.htm - search for com.element.oimo.physics.dynamics and then look for RigidBody nearby... property #12. 

 

Go get em, Bombadilo!  You got the tools to get good and confused now.  :)

Share this post


Link to post
Share on other sites

I know this is rather old but I feel this should be updated so others searching for a solution have up to date information so here ya go.

mesh.getPhysicsImpostor().getLinearVelocity();

To get the velocity of rotation of an object use getAngularVelocity.

mesh.getPhysicsImpostor().getAngularVelocity();

 

Share this post


Link to post
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.