Thank you for your nearly instant responce! :-)
So I changed my handling of collisions for my projectiles in the Update of the physicsscene from:
foreach (ContactConstraint cnt in Simulation.ContactConstraints)
{
if (cnt.BodyA.UserData != null || cnt.BodyB.UserData != null)
{
GameProjectileObject projectileObjA = cnt.BodyA.UserData as GameProjectileObject;
GameProjectileObject projectileObjB = cnt.BodyB.UserData as GameProjectileObject;
if (projectileObjA != null)
projectileObjA.Explode(cnt.BodyB.UserData as GameObject, cnt.LinearConstraintImpulse.ToXna());
if (projectileObjB != null)
projectileObjB.Explode(cnt.BodyA.UserData as GameObject, cnt.LinearConstraintImpulse.ToXna());
}
}
to:
foreach (ContactSet cs in Simulation.CollisionDomain.ContactSets)
{
RigidBody bodyA = cs.ObjectA.GeometricObject as RigidBody;
RigidBody bodyB = cs.ObjectB.GeometricObject as RigidBody;
if (bodyA != null && bodyB != null)
{
if (bodyA.UserData != null || bodyB.UserData != null)
{
GameProjectileObject projectileObjA = bodyA.UserData as GameProjectileObject;
GameProjectileObject projectileObjB = bodyB.UserData as GameProjectileObject;
if (projectileObjA != null)
projectileObjA.Explode(bodyB.UserData as GameObject, projectileObjA.PhysicsEntity.LinearVelocity.ToXna());
if (projectileObjB != null)
projectileObjB.Explode(bodyA.UserData as GameObject, projectileObjB.PhysicsEntity.LinearVelocity.ToXna());
}
}
}
It works but I wonder if there is a better solution to respond to collisions and get the corresponding game object? Do I use UserData correctly?
I always had a problem (before and after the update) with projectiles touching my player character controller if the player moves in the same direction as the (hostile) projectile. The projectile was moving faster before it hits the player but when it should hit the player it moves at the same speed as the player and never explodes (looks like stuck at the outer bounds of the character controller shape).
If the player stops moving in the same direction as the projectile the projectile explodes ...
This problem occurs only if the linear speed difference between the char controller and the sphere projectile is low.
Do you have any idea what's going on there?
Thanks again for your marvelous support!
Lars