Bullet Penetration
by Bryce · in Torque Game Engine · 12/26/2007 (8:24 am) · 10 replies
I've started to mod the engine C++ code to allow bullets to travel through walls. So far I've got it working, but the collision is a little late. Let me explain.
In projectile.cpp, I think the function was ::advanceTick (I don't have the code immediately available, sorry.) that I made my changes. There's a part that calls the OnCollision and Explode functions for the projectile, and just before there's a bit about changing the projectile's velocity (mCurrVelocity) to a Point3F of 0,0,0, which is setting it's velocity to zero, stopping the bullet. I commented out the mCurrVelocity change and the call to explode(), and the rounds do travel through walls. The problem is that they don't immediately hit the player; if a player is on the other side of a thin wall and is right up against it, the bullets travel through the wall AND the player without any damage being done. If I stand back about 20 meters, the bullets do damage the player. Is there something I'm forgetting that is causing this? The bullet is moving very fast, and when I lower the velocity down to about 80 m/s it hits correctly. Help is appreciated.
In projectile.cpp, I think the function was ::advanceTick (I don't have the code immediately available, sorry.) that I made my changes. There's a part that calls the OnCollision and Explode functions for the projectile, and just before there's a bit about changing the projectile's velocity (mCurrVelocity) to a Point3F of 0,0,0, which is setting it's velocity to zero, stopping the bullet. I commented out the mCurrVelocity change and the call to explode(), and the rounds do travel through walls. The problem is that they don't immediately hit the player; if a player is on the other side of a thin wall and is right up against it, the bullets travel through the wall AND the player without any damage being done. If I stand back about 20 meters, the bullets do damage the player. Is there something I'm forgetting that is causing this? The bullet is moving very fast, and when I lower the velocity down to about 80 m/s it hits correctly. Help is appreciated.
#2
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=14044
12/26/2007 (5:52 pm)
BrYcE - I released an unapproved as of yet resource a couple days ago that does this already. You might want to have a look at how I did it.www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=14044
#3
12/27/2007 (2:32 am)
@BrYcE - good to see you getting into the C++
#4
@Chris: I still like Torque Script a lot better. Much easier on the eyes :-p
12/27/2007 (6:19 am)
@Ron: Your resource talks about armor-peircing rounds. Does that mean that you can define materials that it can travel through? The resource looks good, I'll give it a shot sometime.@Chris: I still like Torque Script a lot better. Much easier on the eyes :-p
#5
01/01/2008 (2:42 pm)
You might want to instead change the part in ::processTick that saysif (getContainer()->castRay(oldPosition, newPosition, csmDynamicCollisionMask | csmStaticCollisionMask, &rInfo) == true)
{toif (getContainer()->castRay(oldPosition, newPosition, csmDynamicCollisionMask, &rInfo) == true)
{so it only collides with players, vehicles, and damageable objects.
#6
01/01/2008 (3:55 pm)
No Bryce. My resource bases it on the projectile datablock as to whether it is an aromor piercing round or not. If it is enabled it checks the distance from the impact point to the opposite side. If it is thin enough, the code gives you the ability to have a copy of the original projectile traveling at its original speed on the opposite side of the wall. You can add checks to see if the projectile is travelling fast enough to continue doing ao. The to prevent a projectile from just continuing to travel I added the timed projectile code so you can set a range on it before it just explodes on its own.
#7
Assuming:
Rounds have a penetration value, they can penetrate anything lower than this value.
Rounds have a optimum speed, this speed is the ideal speed for
Materials have a hardness value, the higher this value the harder it is to penetrate.
Materials have a density value, the higher this value the more likely the round may deviate its trajectory and or slow down after penetration.
Hope it helps for the basic algorithm.
11/05/2009 (2:06 am)
Typical realistic game bullet penetration works as follows (pardon the sudo code).Assuming:
Rounds have a penetration value, they can penetrate anything lower than this value.
Rounds have a optimum speed, this speed is the ideal speed for
Materials have a hardness value, the higher this value the harder it is to penetrate.
Materials have a density value, the higher this value the more likely the round may deviate its trajectory and or slow down after penetration.
tick(){
decrease round speed per tick;
if( wallhit ){
if( matHard < roundPen ){
trace through the wall;
kill old round;
make a new round on the other side of the wall with a different speed and vector if changed;
}
}
}Hope it helps for the basic algorithm.
#8
11/05/2009 (2:09 am)
Correction:tick(){
decrease round speed per tick;
if( wallhit ){
kill old round;
if( matHard < roundPen ){
trace through the wall;
make a new round on the other side of the wall with a different speed and vector if changed;
}
}
}
#10
11/06/2009 (3:39 am)
lol not at all :P
Torque Owner Stephan - viKKing - Bondier
TGE (and TGEA) does not support them.
Maybe it is related?