private void Explode() { Vector3 explosionCenter = transform.position; // The center of the explosion radius Collider[] colliders = Physics.OverlapSphere(explosionCenter, radius); // Array of colliders that are within the explosion radius. // For every collider in the explosion radius foreach (Collider hit in colliders) { Rigidbody rbHit = hit.GetComponent <Rigidbody>(); couchPlayerMovement script = hit.GetComponent <couchPlayerMovement>(); if (rbHit != null) { // If the object has a couchPlayerMovement script, set explosion to true in the player's script and disable its constraints before applying the explosive force to it. if (script != null && Vector3.Distance(rbHit.position, transform.position) < maxRagdollDistance) { script.explosion = true; rbHit.constraints = RigidbodyConstraints.None; } // Apply explosion force to object, only if it has a rigidbody component. rbHit.AddExplosionForce(explosionForce, explosionCenter, radius); } } }
public PhysicMaterial heldItemPhysicMaterial; // Physics material used to disable held item's friction and bounciness to reduce collision anomalies void Start() { holdPosition = gameObject.transform.parent.Find("CouchPlayerHoldPosition"); parentScript = gameObject.transform.parent.GetComponent <couchPlayerMovement>(); control = transform.parent.GetComponent <couchPlayerMovement>().control; holdButtonName = control.Interact + transform.parent.GetComponent <couchPlayerMovement>().playerNumber; throwButtonName = control.Throw + transform.parent.GetComponent <couchPlayerMovement>().playerNumber; throwForce = minThrowForce; }
// Use this for initialization void Start() { playerScript = transform.parent.GetComponent <couchPlayerMovement>(); }