- Home /
Bullet Penetration not working
So I have tried to add bullet penetration. Take a look:
private bool isPenetrating;
void OnEnable()
{
isPenetrating = (Random.value > 0.5f);
}
void OnTriggerEnter(Collider col)
{
if (isPenetrating)
isPenetrating = false;
else
Disable();
}
void Disable()
{
gameObject.SetActive(false);
gameController.bulletPool.Enqueue(this.gameObject);
}
The bullet is a trigger. If the bullet collides with something and it is supposed to penetrate, then it will not disable the object and it will turn off the ability to penetrate. When it hits another object, then it will disable. When it is reenabled, then it will have a 50% chance to be able to penetrate.
It does not work! It wont pass through the object at all.
Answer by AlwaysSunny · Aug 31, 2014 at 07:13 AM
Games compute very fast objects like bullets using raycasting. There are exceptions, but the physics simulation of a game only runs N times per second. If a bullet travels D distance in N seconds, and D is greater than the width of your enemy, your wall, etc, no collision is detected.
There is collision. I had this script for a long time. I just added this tiny bit but the bullet does not penetrate a wall one time. I want it to penetrate a wall only one time but it wont penetrate, it just deactivates when it collides.
Your answer
Follow this Question
Related Questions
Wait until audio is finished before set active is false 2 Answers
On TriggerEnter issues 1 Answer
An integer that's supposed to get incremented gets reset when a bullet hits. 0 Answers
mario like cannon 0 Answers
Why do my bullets only destroy themselves sometimes after colliding with the wall? 0 Answers