Collsion impact force and more :)
Posted: Wed Jul 14, 2010 3:35 am
Hey Norbo, I am currently adding in some more collision sounds and particle spats based on impact speed between objects. Since I am doing this I thought that I should fix up my system for calculating collision forces... As it was bad and very inaccurate.
My current system uses this code to approximate the collision force.
This has many issues such as.
1, too slow to run on 100's of objects per frame
2, there is up too a 100ms delay between hitting something and this detecting it
3, horribly inaccurate
4, sometimes doesn’t work at all
I need a system where i can get the collision force (mass * speed) of 2 colliding objects immediately and accurately while still being fast enough to run every frame on 50+ objects, I imagine that i could get the direction of the 2 traveling objects and work out a difference of direction and somehow multiple that with their speeds..? So that if they were going in the same direction and tapped into each other it would return a very diff result to going in opposite directions and colliding.
Also i need to remove part of a static tri mesh during runtime... is this possible or should i convert all those objects to convex hulls and remove them like that? (Or would multiple static tri meshes be faster?)
How you can shed some light on this Norbo
Thanks
My current system uses this code to approximate the collision force.
Code: Select all
private void GenerateCollisionData(ref int in_Count, ref float in_Strength, ref Vector3 in_Norm, ref Vector3 in_Pos)
{
in_Count = 0;
in_Strength = 0;
in_Norm = Vector3.Zero;
in_Pos = Vector3.Zero;
for (int i = 0; i < Bodys[0].collisionPairs.Count; i++)
{
LastKnownFriction = Bodys[0].collisionPairs[i].dynamicFriction;
for (int j = 0; j < Bodys[0].collisionPairs[i].contacts.Count; j++)
{
if (Bodys[0].collisionPairs[i].colliderA.mass == Bodys[0].mass)
in_Norm -= Bodys[0].collisionPairs[i].contacts[j].normal;
else
in_Norm += Bodys[0].collisionPairs[i].contacts[j].normal;
in_Strength += Bodys[0].collisionPairs[i].contacts[j].penetrationDepth;
in_Pos += Bodys[0].collisionPairs[i].contacts[j].position;
in_Count++;
}
}
if (in_Count <= 0) return;
in_Norm /= in_Count;
in_Strength /= in_Count;
in_Pos /= in_Count;
}
1, too slow to run on 100's of objects per frame
2, there is up too a 100ms delay between hitting something and this detecting it
3, horribly inaccurate
4, sometimes doesn’t work at all
I need a system where i can get the collision force (mass * speed) of 2 colliding objects immediately and accurately while still being fast enough to run every frame on 50+ objects, I imagine that i could get the direction of the 2 traveling objects and work out a difference of direction and somehow multiple that with their speeds..? So that if they were going in the same direction and tapped into each other it would return a very diff result to going in opposite directions and colliding.
Also i need to remove part of a static tri mesh during runtime... is this possible or should i convert all those objects to convex hulls and remove them like that? (Or would multiple static tri meshes be faster?)
How you can shed some light on this Norbo

Thanks