Shoot simulation problems
Posted: Fri Nov 05, 2010 8:15 am
Hi. Im new in bepu and I have problems. I create a scene with static floor and few cubes. And im trying apply shoot on cubes using RayCast like this
And here is a questions.
1) Its a correct algorithm to apply impulse on point of object, like weapon shoot?
2) Collision raycast seem incorrect. Only when I displace cursor more to object center it start hit object ! For example
Not hit
Hit

bounding volume seem correct but why RayCast dont hit a physic object ? (also im trying change collision margin but its not help me).
Sorry if my english is bad.
Code: Select all
List<Vector3> hitLocations = Resources.GetVectorList(),
hitNormals = Resources.GetVectorList();
List<float> hitTimes = Resources.GetFloatList();
List<Entity> hitEntities = Resources.GetEntityList();
Vector3 origin = Camera.Position;
Vector3 direction = Camera.WorldMatrix.Forward; // WorldMatrix = Matrix.CreateFromAxisAngle(Vector3.Right, Pitch) * Matrix.CreateFromAxisAngle(Vector3.Up, Yaw);
if (world.RayCast(origin,direction, 1000, true, hitEntities, hitLocations, hitNormals, hitTimes))
{
float earliestTime = float.PositiveInfinity;
int earliestHitIndex = 0;
for (int k = 0; k < hitTimes.Count; k++)
{
if (hitEntities[k] != null && hitEntities[k].CollisionRules.Personal > CollisionRule.Normal)
{
//Don't bother selecting intangible/detector objects.
hitTimes[k] = float.PositiveInfinity;
}
else if (hitTimes[k] < earliestTime)
{
earliestTime = hitTimes[k];
earliestHitIndex = k;
}
}
//valid ray hit
if (hitEntities[earliestHitIndex] != null && hitTimes[earliestHitIndex] != float.PositiveInfinity && hitEntities[earliestHitIndex].IsDynamic)
{
//Apply the force.
Entity body = hitEntities[earliestHitIndex];
float force = 8.0f;
body.ApplyImpulse(hitLocations[earliestHitIndex], Vector3.Normalize(Camera.WorldMatrix.Forward)*force);
}
}
1) Its a correct algorithm to apply impulse on point of object, like weapon shoot?
2) Collision raycast seem incorrect. Only when I displace cursor more to object center it start hit object ! For example
Not hit

Hit

bounding volume seem correct but why RayCast dont hit a physic object ? (also im trying change collision margin but its not help me).
Sorry if my english is bad.
