Quantcast
Viewing latest article 28
Browse Latest Browse All 1264

How to add Rigidbody.AddExplosionForce to propel my player?

I am currently trying to make a movement focused game and I want the player to be able to drop bombs and the bombs should propel the player away from the bomb using Rigidbody.AddExplosionForce. But I'm having an issue where when I add the rigid body to the player the player just falls over, and when I freeze the rotation of the player the player doesn't get propelled away from the bomb. Here is the code for my bomb if anybody was wondering public float delay = 3f; public float radius = 5f; public GameObject explsionEffect; public float force = 700f; float countdown; bool hasExploded = false; void Start() { countdown = delay; } // Update is called once per frame void Update() { countdown -= Time.deltaTime; if (countdown <= 0f && hasExploded == false) { Explode(); hasExploded = true; } } void Explode () { Instantiate(explsionEffect, transform.position, transform.rotation); Collider[] colliders = Physics.OverlapSphere(transform.position, radius); foreach (Collider nearbyObject in colliders) { Rigidbody rb = nearbyObject.GetComponent(); if (rb != null) { rb.AddExplosionForce(force, transform.position, radius); } } Destroy(gameObject); } }

Viewing latest article 28
Browse Latest Browse All 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>