Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » bullet penetration is messing changing how physics is added

bullet penetration is messing changing how physics is added

View previous topic View next topic Go down  Message [Page 1 of 1]


Member [Lv. 2]
Member [Lv. 2]
I am using a ray cast shooting for bullets and i got penetration and physics working just fine until i added a script to limit what it penetrates.

For example i can shoot the top corner and the object will fall but i can't shoo the bottom corner out from underneath.

Current code bellow.

          Vector3 rayOrgin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));        

           RaycastHit[] hits = Physics.RaycastAll(rayOrgin, fpsCam.transform.forward, weaponRange);  
           hitIndex = hits.Length;
           // Effects obkects it hits
           for (int i = 0; i < hitIndex; i++)
               //Deals Damge if item hit has EnemyStats script applied
               EnemyStats dmgScript = hits[i].collider.gameObject.GetComponent<EnemyStats>();

               BulletPenetrate penetrate = hits[i].collider.gameObject.GetComponent<BulletPenetrate>();
               if (penetrate == null)
                   if (dmgScript != null)
                       dmgScript.Damage(gunDamage, hits[i].point);

                   //Applys physics if a item hit has ridgid body component
                   if (hits[i].rigidbody != null)
                       hits[i].rigidbody.AddForceAtPosition(-hits[i].normal * hitForce, hits[i].point);

However when trying to debug I found that the break is what is causing my issue be cause it works just fine when I remove the break from the code.(I am able to shoot the bottom corner out from underneath the object)

I have also tried making i = hitIndex + 1 and making hitIndex = 0 but htey all give me the same result.

Could someone please help me figure out the issue?

I am working on converting some video of what is happening to gifs and willpost those as soon as possible as well.

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum