• Register

The game you are trying to view has ceased development and consequently been archived. If you are a member of this game, can demonstrate that it is being actively developed and will be able to keep this profile up to date with the latest news, images, videos and downloads, please contact us with all details and we will consider its re-activation.

Background and Developers

After waking up a mysterious island with no recollection of how you arrived, you are driven by the basic human instinct to survive. Gather resources, build shelter and live off the land. Tame animals and explore the island. Hunt or be hunted. But most importantly: Survive. However you can.

Wilderness is an open world survival game in development by Dark Window Studios, a dedicated team of developers based in the UK. Check back regularly for updates and changes. Welcome to the Wilderness.


  • View media
  • View media
  • View media
  • View media
  • View media
  • View media
RSS Articles

Bullet Penetration

Feature

Introduction

Bullet penetration is something that is very common in today's AAA games. However, it isn't as common in Indie games as it should be. Settings up a basic system, like the one we use, took about a week and a half, but the result is another layer of immersion and realism. The idea of having bullet penetration may seem like a very complicated subject, having to take many values into account, such as bullet velocity and damage, but thanks to Unity, it can be a lot easier than first anticipated. For our approach, we decided to use raycasting but there are other approaches, such as particle systems.

Bullet Penetration (5.56x45)

As this picture shows, the bullet has declining damage and velocity, which is indicated in the colour strength (Green being high velocity/damage, Red being low velocity/damage). As the bullet passes through each material, the velocity is reduced depending on the material. Here is a comparison of a 9x19mm bullet vs. a 5.56x45mm bullet.

9x19mm Parabellum bullet:

9mm Bullet Penetration

5.56x45mm NATO bullet:

Island 01 11 2016 15 21 screensh

The 9mm bullet fails to punch through two layers of wood, but the 5.56mm bullet powers on through more than 5 layers.

How we did it:

Lets get right into it. Before programming a solution, we needed to set up tags. We already set up a few named "Wood", "Concrete", "Water", ect. for differentiating our footsteps on different materials. However, we want more precise control over material penetration, so we set up a few more tags named "WoodThin", "WoodThick", "ConcreteThin", "ConcreteThick", "MetalThin", "MetalThick" so we could have different penetration values for the same material. We originally looked into calculating the mesh width at that particular angle, but it wasn't practical for runtime. However, Unity has very handy function named Physics.RaycastAll. This sends a ray through all objects for a specified range, logging each collider hit.

Ray ray = new Ray(cam.position, direction);
RaycastHit[] hits = Physics.RaycastAll(ray, 1000.0f);

This returns an array of RaycastHits, a struct that contains information about the hit point and collider that was hit. We can then loop through each of the hits and check information from them.

foreach (RaycastHit hit in hits)
{
     if (hit.collider.tag.ToLower() == "dirt")
     {
          // Do stuff here
     }
}

This is an easy way to loop through the hits and check information. However, we need to record the bullet's current velocity and damage. We just do this via two floats, currentDamage and currentVelocity.

float currentVelocity = 1f;
float currentDamge = 1f;

To simply things, we made a data class named BulletPenetrationStats. This class has a simple constructor, taking in the tag name as a string, bullet damage reduction value, bullet force reduction value and a minimum velocity to penetrate value.

private class BulletPenetrationStats
{
     public string m_sTag;
     public float m_fDamageReduction;
     public float m_fVelocityReduction;
     public float m_fMinimumPenetrateForce;

     public BulletPenetrationStats (string tag, float damageReduction, float velocityReduction, float minPenetrationForce)
     {
          m_sTag = tag;
          m_fDamageReduction = damageReduction;
          m_fVelocityReduction = velocityReduction;
          m_fMinimumPenetrateForce = minPenetrationForce;
     }
}

Earlier in our weapon script, we can declare a private array of variables for each kind of bullet we want, like 9mm High Velocity or 9mm Armour Piercing. For the moment, we just have 9x19 and 5.56x45 rounds balanced and in-game.

private BulletPenetrationStats[] nineMilimetreRoundStats = new BulletPenetrationStats {
    new BulletPenetrationStats ("WoodThin", 0.2f, 0.1f, 0f),
    new BulletPenetrationStats ("Wood", 0.4f, 0.4f, 0.2f),
    new BulletPenetrationStats ("WoodThick", 0.6f, 0.7f, 0.3f),
    new BulletPenetrationStats ("ConcreteThick", 1f, 1f, 1.1f),
}

These aren't representative of the real stats, but a quick example of how we set up the data.

Then, we check at the end of our foreach bracket, looping through the stats and taking away the velocity and damage values. Finally, we check that they are above zero, otherwise we return out of our Shoot function.

BulletPenetrationStats currentStats;
foreach (BulletPenetrationStats entry in nineMilimetreStats)
{
     if (entry.m_sTag.ToLower() == hit.collider.tag.ToLower()
     {
          currentDamage -= entry.m_fDamageReduction;
          currentVelocity -= entry.m_fVelocityReduction;
          currentStats = entry;
          break;
     }
}
if (currentVelocity <= 0 || currentDamage <= 0 || currentVelocity <= currentStats.m_fMinimumPenetrateForce)
{
     return;
}

However, I'm very pedantic about little details. I wanted bullet holes on both sides of the object, so that you could visually trace the path of the bullet. As this foreach statement is run in a single frame, every object is static, so we don't need to worry about accidentally hitting a different object. A single Physics.Raycast will suffice, saving much needed performance on the server side. To calculate the Raycast angle, we just need to take the last hit point away from the current hit point, to get the exact angle needed for the bullet hole on the other side.

Vector3 startPos = hit.point;
Vector3 endPos = lastHitPoint;
Vector3 dir = startPos - endPos;
Ray ray = new Ray(transform.position, dir);
if (Physics.Raycast(ray, 1000f)) {
     // Check surface and instantiate bullet hole
}

Conclusion

And that is a very brief and simple introduction to bullet penetration. It will definitely be taken further and expanded, but this is the depth and complexity required at the moment. One way to expand it would to have a custom shader that has different penetration values, so you could adjust them for each material, but that's an idea for the future. Thanks very much to IRetrograde, who explains it in much more depth than I could. A very handy article on bullet penetration by him can be found here.

Remember to check our Trello Roadmap for real-time updates and follow us on Twitter. Keep Surviving!

Matt

Dark Window Studios

© Dark Window Studios 2015-2016

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account:

X

Latest posts from @wildrnsupdates, @wildernessgame

Merge branch 'release/stresstest-2.0' (04a24387)

May 29 2019 by wildrnsupdates

Stresstest 2.0 has been released to our backers Wilderness.darkwindowstudios.com

Apr 21 2018 by wildernessgame

Build 0.4.0.150

May 10 2017 by wildrnsupdates

Fixed bugs that occured as a result of non-stress test elements being disabled

Apr 28 2017 by wildrnsupdates

Removed objects not being tested in Stress Test 1

Apr 27 2017 by wildrnsupdates

Created new master branch

Apr 27 2017 by wildrnsupdates

Fixed SSAO not toggling or saving

Apr 27 2017 by wildrnsupdates

Fixed compile error

Apr 27 2017 by wildrnsupdates

Removed unused enums

Apr 26 2017 by wildrnsupdates

Updated loading images, namespace improvements

Apr 23 2017 by wildrnsupdates

Tags

Wilderness has not been tagged yet.