- Home /
Why doesn't my grenade go anywere
My grenade when i hit 2 and select it and click to throw it u see the clone come and blows up right in front of u. Basically the object doesn't go a distance.
I fixed it but now if i have my machine gun out it shoots both my machine gun and grenade
Answer by IronWarrior · May 21, 2010 at 10:03 PM
How is the grenade detonated? It depends on what method you're using to blow it up...does it explode after a certain amount of time or due to a collision?
If it's due to a collision, it might be colliding with the character controller that's launching the grenade. To avoid this, you can use Physics.IgnoreCollision between the grenade and the player.
http://unity3d.com/support/documentation/ScriptReference/Physics.IgnoreCollision.html
Answer by Jason_DB · May 22, 2010 at 01:34 PM
Well if its firing both of your weapons at once that means that both weapon scripts are active. Make sure that you have a boolean for each weapon which turns it off (stops it from firing or doing anything) and then only have the weapon you selected be on.
Like DarkHype said the FPS tutorial will explain all of this and includes some neat prebuilt stuff so it's worth checking out especially if you're new to unity (it is a nice introduction to scripting in addition to teaching about FPS's).
Answer by DarkHype · May 22, 2010 at 08:28 AM
You can use FPS tutorial for your problem it explains weapon switching firing rockets and bullet so if i were you i would use that tutorial!
Answer by Kashaunzilla · Apr 28, 2011 at 11:58 PM
Well change from Fire1 button to like Input.GetKeyDown("f") Well here something i put together for throwing your grenade. Just attach to your player.
var grenadePrefab : Transform;
function Update () { if (Input.GetKeyDown("f")) { var grenade = Instantiate(grenadePrefab gameObject.Find("grenadeSpawner").transform.position, Quaternion.identity);
grenade.rigidbody.addforce(forward * 500);
}
}
Ok what you know what you need to is place a empt gameobject where you want your grenade to be thrown from. Place it as a child of the of the maing camera if a fps game and player if it is a 3rd person game. change the 500 to however you want the throwing speed to be, and set the grenade as your grenadePrefab spot. And hit the f key to throw the grenade, when the grenade is spawned it will explode from your own script. That will make your grenade move from the spot. I am pretty sure your have your own grenade exploding script.
Your answer
Follow this Question
Related Questions
multiple raycasts in sphere shape (grenade explosion) 1 Answer
Scripting a grenade 2 Answers
GrenadeScript.cs Troubles 1 Answer
Grenade Script 1 Answer