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);
}
break;
}
}
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?
PS.
I am working on converting some video of what is happening to gifs and willpost those as soon as possible as well.
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);
}
break;
}
}
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?
PS.
I am working on converting some video of what is happening to gifs and willpost those as soon as possible as well.