t0ky00
1
public float radius = 5.0F, power = 10.0F;
void Update()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
if (Input.GetMouseButtonDown(0))
{
Shoot();
}
}
void Shoot()
{
Vector3 fwd = muzzle.TransformDirection(Vector3.forward);
RaycastHit hit;
if (Physics.Raycast(muzzle.position, fwd, out hit, Mathf.Infinity))
{
Vector3 explosionPos = hit.point;
Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
foreach (Collider c in colliders)
{
Rigidbody r = c.GetComponent<Rigidbody>();
if(r != null)
r.AddExplosionForce(power, explosionPos, radius);
if (c.gameObject.tag == "Body" || c.gameObject.tag == "Head")
{
LimbDamage _ld = c.transform.gameObject.GetComponent<LimbDamage>();
if (!_ld._eh.dead)
{
_ld.KillByRailgun();
}
}
}
}
}
When ever i click the mouse button it affects a certain amount of objects for a short amount of time and then it stops completely. Everything is set up , the raycast works , the colliders are there , the tags are there , this should work…
t0ky00
2
Well i found a fix , this specific line caused the issue for some reason
if (c.gameObject.tag == "Body" || c.gameObject.tag == "Head")
{
LimbDamage _ld = c.transform.gameObject.GetComponent<LimbDamage>();
if (!_ld._eh.dead)
{
_ld.KillByRailgun();
}
}
Basically i just changed it to -
if (Physics.Raycast(muzzle.position, fwd, out hit, Mathf.Infinity))
{
Collider[] colliders = Physics.OverlapSphere(hit.point, radius);
foreach (Collider c in colliders)
{
Rigidbody r = c.GetComponent<Rigidbody>();
if (r != null)
{
print(r.gameObject.name);
r.AddExplosionForce(power, hit.point, radius, 3f);
LimbDamage _ld = c.transform.gameObject.GetComponent<LimbDamage>();
if (_ld != null)
{
_ld.KillByRailgun();
}
}
}
}
No idea why the one above didn’t work…