Continuous / Bullet Collision Detection
by Alex Stittle · in Torque X 3D · 01/16/2009 (4:06 pm) · 9 replies
Does Torque X support Continuous Collision? I think that's what it's called....
Basically, I fire a bullet a wall at a speed of 3000 m / s. Since the bullet is moving so fast, in the first frame it's on one side of the wall, and on the second frame it's on the other side of the wall. Effectively, the bullet went 'through' the wall in a single frame.
Since the collision box of the bullet didn't overlap with the collision box of the wall, there is no collision detected.
If anyone knows, or knows a hack for the code, to set certain objects to have Continuous Collision Detection, that would be most appreciated :)
Basically, I fire a bullet a wall at a speed of 3000 m / s. Since the bullet is moving so fast, in the first frame it's on one side of the wall, and on the second frame it's on the other side of the wall. Effectively, the bullet went 'through' the wall in a single frame.
Since the collision box of the bullet didn't overlap with the collision box of the wall, there is no collision detected.
If anyone knows, or knows a hack for the code, to set certain objects to have Continuous Collision Detection, that would be most appreciated :)
#2
Maybe I'll build a shooting wall to do further testing.
There might be a solution in using interpolate ticks... I'll check it out when I have some time. Right now this isn't my biggest problem :) I'll post back here if I find anything.
01/17/2009 (1:15 pm)
I 'sort of' tested it. I certainly didn't do any strenuous testing but I do have a game where I fire bullets and kill guys (I know, so original). If I shoot the bullets slowly, then the collisions are fine. Fast and they don't seem to collide at all.Maybe I'll build a shooting wall to do further testing.
There might be a solution in using interpolate ticks... I'll check it out when I have some time. Right now this isn't my biggest problem :) I'll post back here if I find anything.
#3
01/17/2009 (3:37 pm)
Cool, I'll check back every so often.
#4
Otherwise, you can try to approximate the bullet's impact in a way that is more friendly to Torque X's tick processing. For example, you can create a bounding box for the bullet that has a long tail (imagine an invisible bullet tracer tail), so that on the next tick processing, some of the bounding box is still colliding with the wall. The faster your bullet is travelling, the longer that bounding box tail should be to improve your chances of it recognizing the collision on the tick.
John K.
www.envygames.com
01/18/2009 (9:38 pm)
Torque X does not support a bullet physics solution since it's largely based on tick processing. The tick interpolation could help, but that's more for addressing network latency. If you really need bullet physics, I've heard about a lot of projects integrating a third party physics solution such as www.bulletphysics.com. Otherwise, you can try to approximate the bullet's impact in a way that is more friendly to Torque X's tick processing. For example, you can create a bounding box for the bullet that has a long tail (imagine an invisible bullet tracer tail), so that on the next tick processing, some of the bounding box is still colliding with the wall. The faster your bullet is travelling, the longer that bounding box tail should be to improve your chances of it recognizing the collision on the tick.
John K.
www.envygames.com
#5
I was actually thinking of doing the bullet concept with the same idea you came up with. However, I think there might be a problem with it in the case of a bullet 'falling' down a slope. I'm not sure if the bounding boxes are axis-aligned or not, but I think in this scenario a collision will be detected when it shouldn't be.
Say you fire a bullet going 'right' and it comes to a hill, so it has to follow the hill down for some reason. But the bullet has no rotation, also for some reason (maybe it's a special terrain following hover bullet). Then when it comes to the edge of a downslope, as soon as it goes 'down', then the tail would collide with the terrain. When it really didn't collide with anything.
Man, I stink at explaining so let me try some ascii art. (EDIT: Ascii art was FTL).
The best example I can think of is pushing a box down a slope, but the box doesn't rotate. So the tail (sticking out of the back of the box), hits the slope.
I haven't actually implemented the idea (mostly because I don't know how to yet), so this might not happen, but it just came to mind.
The other way I was going to do it was to do a line intersection from the previous point to the current point. It won't be 100% accurate, and it won't work for curving bullets, but it might be OK for a simple test. Unfortunately, I don't know how to implement this concept either :( I'm still new and messing around with the classes and such.
01/19/2009 (9:25 am)
Well, so much for my testing haha. Thanks for the info John.I was actually thinking of doing the bullet concept with the same idea you came up with. However, I think there might be a problem with it in the case of a bullet 'falling' down a slope. I'm not sure if the bounding boxes are axis-aligned or not, but I think in this scenario a collision will be detected when it shouldn't be.
Say you fire a bullet going 'right' and it comes to a hill, so it has to follow the hill down for some reason. But the bullet has no rotation, also for some reason (maybe it's a special terrain following hover bullet). Then when it comes to the edge of a downslope, as soon as it goes 'down', then the tail would collide with the terrain. When it really didn't collide with anything.
Man, I stink at explaining so let me try some ascii art. (EDIT: Ascii art was FTL).
The best example I can think of is pushing a box down a slope, but the box doesn't rotate. So the tail (sticking out of the back of the box), hits the slope.
I haven't actually implemented the idea (mostly because I don't know how to yet), so this might not happen, but it just came to mind.
The other way I was going to do it was to do a line intersection from the previous point to the current point. It won't be 100% accurate, and it won't work for curving bullets, but it might be OK for a simple test. Unfortunately, I don't know how to implement this concept either :( I'm still new and messing around with the classes and such.
#6
01/19/2009 (9:41 am)
Cast a ray from the bullet's old position to its current position. Works good.
#7
Also, with ray casting, I assume I can call the bullet's OnCollision delegate method if there is one for the ray?
01/19/2009 (2:35 pm)
Sounds good to me, but I'm not sure how to cast a ray with Torque yet. I'll do some investigating and see if I can't figure it out.Also, with ray casting, I assume I can call the bullet's OnCollision delegate method if there is one for the ray?
#9
The code for the rayCast is as follows:
01/19/2009 (9:10 pm)
Ok, did some ray cast hunting and came up with a solution. It works, but I am not sure how to get the contact points and number of contacts. If anyone could fill me in, it would be much appreciated.The code for the rayCast is as follows:
// Create the ray, giving it a starting point and direction, as well as a max length
RayCastQueryData ray = new RayCastQueryData();
Vector3 dir = Vector3.Subtract(_ownerSceneComponent.Position, _previousPosition);
ray.Direction = dir;
ray.Position = _previousPosition;
ray.Length = 1.0f;
ray.IgnoreObject = this.Owner; // Don't let the ray intersect with the bullet
// Check for a collision in the scene
bool isCollision = _ownerRigidComponent.RigidManager.CollisionScene.CastRay(ray);
// Assuming there is a collision, go through all the objects that the ray collided with. I currently ignore the terrain.
// With whatever is hit, call the collision delegate method
if (isCollision && ray.ResultList != null)
{
for (int i = 0; i < ray.ResultList.Count; i++)
{
// Extract the object name of the object we collided with
String objectName = ray.ResultList[i].RigidComponent.Owner.Name;
// Ignore the Terrain object for now
if (!objectName.Contains("Terrain"))
{
// Call the projectile's collision method (sorry, I don't yet know how to extract the contact point information)
_collisionDelegate(_ownerRigidComponent, ray.ResultList[i].RigidComponent, null, 0, ray.Time);
break;
}
}
}
Torque Owner Brian Bond