Page 1 of 1
Problems with GrabSpring class and damping.
Posted: Wed Feb 16, 2011 2:47 pm
by Spankenstein
I've changed the constructor values for the GrabSpring class to move entities about without them flying about wildly:
Code: Select all
CorrectionFactor = 300f;//correctiveStrength;
LinearDamping = 1f;//linearDamp;
AngularDamping = 1f;//angularDamp;
Although the entities now move as I would like, when the grab spring is released they freeze in mid air and gravity has no effect on them until another entity comes into contact with them.
How can this be fixed?
Re: Problems with GrabSpring class and damping.
Posted: Wed Feb 16, 2011 9:13 pm
by Norbo
That's being caused by the sleeping system. It sees that the object has very low velocity for sufficient time that it should be deactivated. While it's held by the grabspring, it is continually activated. One way to address this is by changing the space.SimulationSettings.Deactivation settings to either have a lower velocity threshold or wait longer to deactivate. Another way that doesn't require changing global settings is to simply activate the entity after it's been released.
Re: Problems with GrabSpring class and damping.
Posted: Wed Feb 16, 2011 11:14 pm
by Spankenstein
I thought it might have something to do with that but the IsActive property is still true when letting go of the object:
Code: Select all
public void ReleaseGrabbedEntity()
{
IsUpdating = false;
// Entity will deactivate if velocity is low due to damping
// Activate the entity to wake it up again so it can be affected by gravity
Entity.IsActive = true;
//game.Space.Entities[game.Space.Entities.IndexOf(Entity)].IsActive = true;
Entity = null;
}
Is there another property that wakes the object up without applying forces?
Re: Problems with GrabSpring class and damping.
Posted: Thu Feb 17, 2011 12:17 am
by Norbo
Is there another property that wakes the object up without applying forces?
No, that should work. The methods that wake objects up with forces just use a form of that property internally. Something a little different may be happening. It could be that the grabspring's damping is still around from the previous frame. Despite being forced active right before that frame, it will go right back to sleep if it still has extreme damping.
Slightly weakening the damping, changing the location of the extra activate, or tuning the deactivation system might help.
Another option would be to set the entity's IsAlwaysActive to true for the duration of the hold. This prevents any 'low velocity' time from accumulating, so that when the entity is released, it has some time to get speed and avoid deactivation.
Also, using an extremely strong grabspring like that is hard to handle in the simulation. It's intended just to be a simple grabber. Using a SingleBody(Angular/Linear)Motor to control the position/orientation of an entity, possibly through the EntityMover/EntityRotator convenience classes, would be more robust. Additionally, the damping in these systems is built into the solver and would not encounter the same 'last frame damping' issue.
Re: Problems with GrabSpring class and damping.
Posted: Thu Feb 17, 2011 12:21 pm
by Spankenstein
Another option would be to set the entity's IsAlwaysActive to true for the duration of the hold.
Unfortunately this suggestion doesn't work and the Entity remains asleep.
Using a SingleBody(Angular/Linear)Motor to control the position/orientation of an entity, possibly through the EntityMover/EntityRotator convenience classes
The EntityMover class requires a non null Entity in its constructor, so I have opted to use the SingleEntityLinearMotor class instead.
Code: Select all
public ObjectMover(Game1 game)
{
this.game = game;
motor = new SingleEntityLinearMotor();
motor.IsActive = false;
game.Space.Add(motor);
}
I've searched through the BEPU demo code and could only find a line drawing class for this motor class. I can now draw the line along which to pull with:
Code: Select all
public void Draw()
{
if (!motor.IsActive)
{
return;
}
game.WireShapeDrawer.DrawLine(motor.Entity.InternalCenterOfMass, motor.Point, Color.Red);
}
I'm not understanding the setup correctly though:
Code: Select all
public void Setup(Entity e, Vector3 grabLocation, Vector3 offset)
{
motor.IsActive = true;
motor.Entity = e;
motor.LocalPoint = offset;
motor.Point = grabLocation;
}
How can I set up the motor so that it moves the entity to the correct mouse point in a similar manner to the GrabSpring? I couldn't find any documentation on this.
Thank you.
Re: Problems with GrabSpring class and damping.
Posted: Thu Feb 17, 2011 10:53 pm
by Norbo
I'll create an example "MotorizedGrabSpring" today. Two, actually; one for v0.14.3, one for v0.15.0. The v0.14.3 version requires a few extra bits to get working as you'll see.
Re: Problems with GrabSpring class and damping.
Posted: Thu Feb 17, 2011 11:06 pm
by Spankenstein
That's very kind of you. Thank you. I look forward to reading the code

Re: Problems with GrabSpring class and damping.
Posted: Fri Feb 18, 2011 12:00 am
by Norbo
Here they are. The default configuration is a fairly rigid spring with a maximum force. It will keep stuff near the desired location without ramming through solid objects all the time. You may need to increase its strength to handle heavier objects; configuring the strength on a per-entity basis would enable the constraint to carry all objects with similar behavior if that's what you want.
The difference between the v0.14.3 and v0.15.0 is in how the motor's entity is managed. v0.14.3 doesn't like accepting null entities for single-entity constraints, and the entity isn't forced awake when the motor changes its target. These two issues are addressed in the v0.14.3 version by providing a fake entity and manually forcing the object awake on release.
The v0.15.0 sample is actually made for tonight's build of v0.15.0, so you may have some issues if you try it with the currently published Beta 15
