- Home /
Add force to an explosion...
Hi all i just want to ask how to add force to an explosion prefab which comes with unity and would like to know how to call the explosion on the click of the mouse button. this is how i want it to be like:
there are 5 boxes in the scene all boxes have rigidbody now when i click the mouse i want the explosion prefab to play. Now if the explosion is next to the boxes i want the boxes to move away and etc. And finally when i click on the mouse button anywhere on the screen that is where i want the explosion to happen
thanks in advance :)
Answer by networkZombie · Mar 20, 2011 at 11:33 PM
the FPS tutorial shows you how to to this. But Why do you want to use the explosion that comes with unity? Download the Detonator Package from the asset store. the explosions are WAY more realistic and they add force to nearby rigidbodies too. you can even make customized explosions with that.
if(hit.rigidbody){
var force = 1000;
hit.rigidbody.Addforce(Vector3.forward * force); }
i know but i would like to know how to do it for myself, as for the explosion its just for test reasons :)
Answer by efge · Mar 21, 2011 at 04:40 PM
Some starting points (if you want do it for yourself):
Ask if a mouse button is pressed with Input.GetMouseButtonDown, make a Physics.Raycast with a ray from the camera to the mouse click with Camera.main.ScreenPointToRay (Input.mousePosition) and then use networkZombie's answer or use Rigidbody.AddExplosionForce.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Prefab (Project Folder) to a GameObject (on the Scene) 2 Answers
my unity is freezing when adding prefab to script 1 Answer
Is it possible to edit the sub-sub-GameObjects of a prefab in the assets window? 1 Answer
How do i have explosion effect after my object destroyed? 3 Answers