Page 1 of 1

Entities are always active

Posted: Fri Sep 21, 2012 10:36 pm
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.

Re: Entities are always active

Posted: Fri Sep 21, 2012 10:51 pm
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.

Re: Entities are always active

Posted: Fri Sep 21, 2012 11:21 pm
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.

Re: Entities are always active

Posted: Fri Sep 21, 2012 11:30 pm
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.

Re: Entities are always active

Posted: Sat Sep 22, 2012 1:32 am
by tehDrop
Thanks, that's much better.