Entities are always active

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
tehDrop
Posts: 20
Joined: Sat Dec 03, 2011 3:58 am

Entities are always active

Post by tehDrop »

Hi, I was looking through the demos and noticed that entities become deactivated when they have no velocity. Then I found that each space has a DeactivationManager that is supposed to do that.

However in my game, entities are always active even with very high VelocityLowerLimit values... Also I never used IsAlwaysActive and everything related to deactivation is set to default.

Does anyone know why this is happening?

Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entities are always active

Post by Norbo »

Is anything changing entity properties every frame? Setting velocity, momentum, position, and orientation (or equivalent properties) will wake an entity up. There are some other actions which could cause an entity to wake up; in general, if the simulation needs to run to understand a change, the entity will wake up to accommodate it.

If that's not it, can you reproduce it in an isolated demo (perhaps a modified BEPUphysicsDemos demo)? That should make the cause clearer.
tehDrop
Posts: 20
Joined: Sat Dec 03, 2011 3:58 am

Re: Entities are always active

Post by tehDrop »

Thanks. I found it:

Code: Select all

      
foreach (BEPUphysics.Entities.Entity k in collisionSpace.Entities)
{
      k.LinearVelocity = Vector3.Clamp(k.LinearVelocity, new Vector3(-15), new Vector3(15));
}
I'm thinking about just adding

Code: Select all

if(k.LinearVelocity.Length() > 15)
I don't if there's a more optimized way to limit the velocity though.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entities are always active

Post by Norbo »

Chances are it won't be a performance bottleneck (at least on the PC), but you could hook into the entity.PositionUpdated event. It only fires when the entity is active and a position update occurs. The event is fired after the position is integrated so it won't stop a momentary violation, but it's no different from limiting the velocity externally in that respect.

Edit: Adding in a check to avoid setting the linear velocity is still valuable though. Checking the entity.ActivityInformation.IsDeactivationCandidate would tell you if it's a nearly stopped object that's trying to go to sleep. If the IsDeactivationCandidate property is true, the linear velocity does not need to be set.
tehDrop
Posts: 20
Joined: Sat Dec 03, 2011 3:58 am

Re: Entities are always active

Post by tehDrop »

Thanks, that's much better.
Post Reply