Page 1 of 1

Collision Detection

Posted: Tue Jun 05, 2012 1:28 pm
by SniperED007
I have a camera and I've created a Sphere and assigned it's position to the Camera Position, but when the sphere collides with a static mesh I want the camera to stop moving.
How do I go about doing this?

I tried the following:

in my initializing...
sphere = new Sphere(Camera.Position, 1, 1);
sphere.IgnoreShapeChanges = true;
sphere.PositionUpdateMode = PositionUpdateMode.Continuous;
sphere.CollisionInformation.Events.DetectingInitialCollision += RemoveFriction;
sphere.LocalInertiaTensorInverse = new Matrix3X3();
sphere.LinearDamping = 0;
space.Add(sphere);

in my update:

CameraMovement(); // re-position the camera in it's new position
space.Update();
lastPosition = Camera.Position;

in

void RemoveFriction(EntityCollidable sender, BroadPhaseEntry other, NarrowPhasePair pair)
{
var collidablePair = pair as CollidablePairHandler;
if (collidablePair != null)
{
Vector3 direction = Vector3.Normalize(Camera.Position - lastPosition);
Camera.Position = Camera.Position - (direction * collidablePair.Contacts[0].Contact.PenetrationDepth);

collidablePair.UpdateMaterialProperties(new InteractionProperties());
}
}

But that doesn't seem to work, what should I be doing here?

Thanks,
ED

Re: Collision Detection

Posted: Tue Jun 05, 2012 2:14 pm
by Norbo
Setting the position of an entity teleports it, preventing collision response from doing its job.

The camera should follow the entity. So, instead of setting the sphere's position to the camera's position, set the camera's position to the sphere's position and use your input to control the velocities of the sphere.

Re: Collision Detection

Posted: Tue Jun 05, 2012 3:09 pm
by SniperED007
thanks, just converted it and it works perfectly! Thanks for the quick response!
Looking forward to using BEPU a lot more in our games!