Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Granade script

$
0
0
Hi people. I need a good granade script for my game. the actual script what i'm using is this: public class BulletSc : MonoBehaviour{ [SerializeField] public Rigidbody rb; [SerializeField] public GameObject bulletGo, explosionEffect; [SerializeField] bool useGrav, collisionExplosion; [SerializeField] float explosionCoundown, explodingTime, explosionRadius, explosionForce; float explosionTime, isExplodingTime; GameObject ignore; bool isExploding; void OnEnable(){ isExploding = false; explosionTime = Time.time + explosionCoundown; rb.useGravity = useGrav; bulletGo.SetActive(true); explosionEffect.SetActive(false); } void Update(){ if(explosionTime < Time.time && !collisionExplosion && !isExploding){ isExplodingTime = Time.time + explodingTime; isExploding = true; } if(isExploding && isExplodingTime < Time.time) this.gameObject.SetActive(false); if(isExploding) Boom(); } void OnCollisionEnter(Collision col){ if(ignore == null && col.gameObject.tag == "Weapone") ignore = col.gameObject; if(col.gameObject != ignore && collisionExplosion){ isExplodingTime = Time.time + explodingTime; isExploding = true; } } void Boom(){ rb.useGravity = false; rb.velocity = new Vector3(0,0,0); bulletGo.SetActive(false); explosionEffect.SetActive(true); Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius); foreach(Collider nearbyObject in colliders){ Rigidbody noRb = nearbyObject.GetComponent(); if(noRb != null && noRb != rb){ noRb.AddExplosionForce(explosionForce, transform.position, Mathf.Lerp(0, explosionRadius, explosionTime * 2)); } } } } but, the character controllers are not included, and this method of explosion isn't realistic

Viewing all articles
Browse latest Browse all 592

Trending Articles