Page 1 of 1

A possible bug and it haunts me crazy

Posted: Thu Jan 05, 2017 5:15 am
by yanbo2u
Finally, I can reproduce it.
in LoadContent() function, simply add a box

Code: Select all

Box test0 = new Box(Vector3.UnitY + Vector3.UnitX * 2, 2, 2, 2, 1);
AttachWithSkin(game, test0, CubeBlue);
space.Add(test0);
wait after 5 seconds or more (this is very important).

and then apply an impulse to the box

Code: Select all

if (KeyboardState.IsKeyDown(Keys.Enter) )
{
	Vector3 p0 = Vector3.UnitX * 100 * space.TimeStepSettings.TimeStepDuration;
	test0.ApplyLinearImpulse(ref p0);
}
the box is supposed to accelerate in the direction of X, but it does not move at all.

I looked into the LinearVelocity value of the box, it does increases under impulses, but the position is stationary.

However, if I use another object to shoot at this box test0, it starts moving like waking up by the collision.

Re: A possible bug and it haunts me crazy

Posted: Thu Jan 05, 2017 5:26 am
by Norbo
Objects at rest go to sleep to conserve compute resources. ApplyLinearImpulse and ApplyAngularImpulse do not affect the activity state by design; they are direct low-overhead methods used by the solver to change the velocity of the entity.

Changing an entity's properties like LinearMomentum, AngularMomentum, LinearVelocity, or AngularVelocity will wake it up. Note that ApplyLinearImpulse(ref v) is equivalent to entity.LinearMomentum += v.

You can also directly wake up an entity by setting entity.ActivityInformation.IsActive = true.

Re: A possible bug and it haunts me crazy

Posted: Thu Jan 05, 2017 5:36 am
by yanbo2u
ApplyLinearImpulse(ref v) is equivalent to entity.LinearMomentum += v.
Thanks Norbo! It works like a charm.