Constraint Problem

Jan 1, 2010 at 9:15 PM


i have just downloaded the framework, it looks great and useful, thanks for your engine! I like it

For my xna project, i create a machine to absorb and release the ball. The example6 seems useful for this. However, i have some problem while coding.

i decided the player can start and stop to absorb the ball. i was wondering that can i stop the absorb function by remove the constraint?

the other question is how can i detect the collision between the two object? i have find out the CollisionDetectors class, but i'm too noob that i don't know how to use it. is there any example for the collision detection?

the version is 32323 with XNA3.0, Thanks for attention!

public override void Update(GameTime gameTime)

if (this.InputService.IsKeyDown(Keys.Space))
for (int i = 0; i < spheres.Count; i++)
PointToPointConstraint constraint = new PointToPointConstraint();
constraint.RigidBody0 = box.CollisionGroup.RigidBody;
constraint.RelativePosition0 = Vector3.Left * (0.5f);
constraint.RigidBody1 = this.spheres[i].CollisionGroup.RigidBody;
constraint.RelativePosition1 = Vector3.Left * (this.spheres[i].Radius + 0.5f);
constraint.Tolerance = 1.0f;
constraint.Timescale = 1.0f;

if (this.InputService.IsKeyDown(Keys.LeftControl))
foreach (PointToPointConstraint constraint in constraints)
constraints.RemoveRange(0, constraints.Count);

Jan 2, 2010 at 5:19 AM
Edited Jan 2, 2010 at 5:20 AM

First, if you want to to enable/disable a constraint, I would add the constraint at initialization and use the Constraint.Flags to enable (constraint.Flags |= ConstraintFlags.Disabed) and disable (constraint.Flags &= ~ConstraintFlags.Disabled).  I do not remember if this flag exists in version 32323 though.  If not, I would suggest that you try to ugrade if possible. 

Second, your code above will get called too aften because of the use of IInputService.IsKeyDown.  You probably mean to IInputService.IsKeyPressed, which will check if the key was pressed during that frame instead of just held down.

See my response to this discussion, which briefly discusses the options for collision notification.

Jan 7, 2010 at 11:57 PM

Thank you for your fast reply

It is useful!