x


Would this work for melee in an FPS?

If I created a weapon similar to the grenade launcher from the FPS tutorial, could I make it shoot an invisible sphere collider instead of a sphere, and set that collider to disappear after a second or so (thereby only functioning in "melee range")?

Would this work?

more ▼

asked Feb 17 '10 at 04:33 PM

PrimeDerektive gravatar image

PrimeDerektive
3.1k 57 64 84

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

1 answer: sort oldest

I guess it would work but here is how i did my melee attack (keep in mind it is more or less a suicide bomber, it charges you, when it gets in range it blows up dealing damage):

//set player as your player
var player : Transform;
//distancePlayer is how far away it is before it deals damage
var distancePlayer : float = 2;
//this should be obvious
var damage : int = 5;
//as it is a suicide bomber it will create this when it goes boom.
var blowup : Transform;


function Update () {
//sets the calculations 
var distFromPlayer : Vector3 = player.position - transform.position;
//checks to see if the player is in range
if(distFromPlayer.magnitude < distancePlayer) {
//deals damage, though this works with my other script which is long and complicated
new MessagePlayerHit(damage);
//makes the explosion particle system, probably not useful for you
Instantiate(blowup, transform.position, Quaternion.identity);
//destroys the enemy, also probably not useful for you
Destroy (gameObject);
}
}

Hope this helps you out!

more ▼

answered Feb 17 '10 at 07:20 PM

xToxicInferno gravatar image

xToxicInferno
485 24 28 41

(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:

x5096
x1707
x181

asked: Feb 17 '10 at 04:33 PM

Seen: 1719 times

Last Updated: Feb 17 '10 at 04:33 PM