x


Ai that applies damage when in range?

Hi, I'm making a FPS based from the FPS tutorial and has made a basic ai that follows me and maintains a constant distance between it and the character. Does anyone has an idea on how to make the Ai apply damage over time if it is in range with the player? I'm a total noob on scripting and just need a rough guideline to continue it...thanks!

more ▼

asked Nov 20 '10 at 10:27 AM

user-3061 (yahoo) gravatar image

user-3061 (yahoo)
126 29 29 37

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

1 answer: sort voted first

the best way IMO : you gonna need a trigger that will be attached on your enemy. Use the OnTriggerStay function, if statement the object in it have the tag "Player", (set your player object to have that tag) if it does, use SendMessage to call a damage function in your player(this damage function can be found in scripts like CharacterDamage in the FPS tutorial). Now you have it sending the damage. All you gotta do then is limit how often the if statement should be read (example on the rocket launcher script in the FPS tutorial for this). that is, make 2 float variables, one called dmgFrequency and another called hitTime. your if statement gonna end like this

if(col.gameObject.tag ==("player") && hitTime+dmgFrequency < Time.time){

col.SendMessage("ApplyDamage", 1);

hitTime= Time.time;

}

being col the variable that is in contact with the trigger.

http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=trigger

more ▼

answered Nov 20 '10 at 12:54 PM

Bravini gravatar image

Bravini
1.1k 6 11 29

so now i need to make the enemy actually collide with my player? I'm actually preventing his, because im making an FPS, so if the enemy collides to the player, it would be too close to the camera.that's why i maintained a distance between the player and the enemy. What i mean is that I need a script that can apply damage from a small range, without colliding to the player. Is there any way to some kind o fake collider that just senses the player if its in range, and apply damage from time? thanks for the answer!

Nov 21 '10 at 02:46 AM user-3061 (yahoo)

triggers are exactly that, they don't react phisycally, so the objects go through them, think of it as a zone. You can set a trigger scale as you wish too.

Nov 21 '10 at 10:14 PM Bravini

ok, il try that, thanks!

Nov 22 '10 at 01:38 AM user-3061 (yahoo)
(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:

x1174
x960
x383
x248
x106

asked: Nov 20 '10 at 10:27 AM

Seen: 1376 times

Last Updated: Nov 20 '10 at 10:27 AM