x


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

more ▼

asked May 21 '10 at 08:32 PM

user-2679 (yahoo) gravatar image

user-2679 (yahoo)
1 2 2 4

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

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

more ▼

answered May 21 '10 at 10:03 PM

IronWarrior gravatar image

IronWarrior
73 1 1 6

(comments are locked)
10|3000 characters needed characters left

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).

more ▼

answered May 22 '10 at 01:34 PM

Jason_DB gravatar image

Jason_DB
1.9k 4 14 36

(comments are locked)
10|3000 characters needed characters left

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!

more ▼

answered May 22 '10 at 08:28 AM

DarkHype gravatar image

DarkHype
37 4 4 12

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 28 '11 at 11:58 PM

Kashaunzilla gravatar image

Kashaunzilla
34 17 19 28

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x23

asked: May 21 '10 at 08:32 PM

Seen: 1004 times

Last Updated: May 21 '10 at 11:25 PM