Jump to content

Is there a command to check if a physics body has come to rest ?


Wchris
 Share

Recommended Posts

If not maybe in LE3 ? ^^

 

if not how would you simulate this test with LE2 ? (without false detections when a body is thrown in the air and reaches the point where he falls down)

 

Thanks

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

LE::TVec3 velocity = LE::GetBodyVelocity(LE::TBody)

LE::TVec3 omega = LE::GetBodyOmega(LE::TBody)

 

When both velocity & omega = (0,0,0) or very close to the body is at rest.

  • Upvote 1

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

If it's possible to determine that a body was thrown in the air (just like the user presses a certain key),

you could set a flag that tells your code that the body was thrown.

Now you can check if your velocity and rotation is near 0 and just ignore it, if the flag is set.

You could apply the same for a bouncing object. Just use the collision callback and check if the force is

sufficient to get the body airborne again. If so, set the flag again.

 

I do not recommend to check any float value against 0.0f.

Normally you would define a small value beyond which you assume it's zero.

 

The way i would do it:

// Global
const float cfMinVelocity = 0.01f;
// For each throwable body
bool bAirborne = false;
// Check if the velocity reaches zero
LE::TVec3 Vel = LE::GetBodyVelocity(TheBody);
float fVelocity = (float)sqrt(Vel.X*Vel.X + Vel.Y*Vel.Y + Vel.Z*Vel.Z);
if (fVelocity <= cfMinVelocity)
{
 if (!bAirborne)
 {
	 // Object is not airborne/thrown and has stopped moving
 }
 else
 {
	 // Object is airborn/thrown and has stopped moving
 }
}

 

You can even get rid of the square root and check against cfMinVelocity*cfMinVelocity to get

maximum performance =)

 

Edit:

Assume a player that can shoot a ball that then bounces off other objects.

The player shoots the ball and you set the flag bAirborne to true.

Now the ball flies around and finally hits an object. The collision callback of

the ball will be called and you can set bAirborne to false. If the collision speed

was fast enough, you set bAirborne to true again, because the ball will become

airborne again.

  • Upvote 1

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

Thank you all

Maybe I can also check collision to determine if the body is airborne or not. I assume a collision occurs when the body is grounded.

 

I'll experiment a bit

You should take the direction of the body's current velocity into account. Just relying on collisions will cause "bugs".

Imagine an already airborne body hitting the ceiling...

  • Upvote 1

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

Thank you Dadonik for the complete code sample.

 

I used your code with sqrt formula + collision detection (to know if all 4 foots are grounded to the right place) and it works perfectly.

 

smile.png

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

In bmax there is a method that can be used on bodies to check if it has come to rest or not, body.Active() and it looks like something of it was exposed at one point to lua as BodyActive() / BodyFrozen() but neither appear to work - unless there is some particular thing I am missing in its usage to get it to work. But if it doesnt work in lua, i suspect it wasn't ever introduced to c++.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

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...