x


area of effect stuff

Hi,

I Want to make some GameObjects that, say, increase a variable in another GameObject the closer and more they are.

Like magic mushrooms with a healing aura. The player's gameObject regenerates the variable "health" faster the closer a mushroom is, but also the more mushrooms there are.

How can I check for the proximity of my mushrooms in the Player character's game object? In my game, there are hundreds of aura-things affecting a maximum of 8 other objects so it needs to be efficient.

I also want to set an aura-range in the player's game object to determine the falloff radius of the mushroom's effect.

more ▼

asked Feb 25 '12 at 04:36 PM

Somian gravatar image

Somian
206 35 46 52

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

1 answer: sort oldest

Triggers!!

Yes, it wouldn't be very effective measuring distance to every mushroom, every frame. So, in my game I would add a trigger to my player. Create a script and check if a mushroom entered the trigger(I am sure you are familiar with triggers. If not, look them up in the Scripting Reference). Once a mushroom has entered the trigger, then measure distance to the mushroom(s) and add health accordingly. Remember, you don't have to measure distance every frame, maybe do twice a seconds. Then add more health the closer the mushroom is to the player.

more ▼

answered Feb 25 '12 at 04:52 PM

OrangeLightning gravatar image

OrangeLightning
5.4k 47 57 112

Thanks! triggers are a great Idea!

one question though: how can I do something twice a second?

Feb 25 '12 at 04:59 PM Somian

Something like so:

if(mushroom is in trigger){
Invoke("CalculateDistance", 0.5);
}

function CalculateDistance(){
 // Measure distance to each mushroom
}

Alternatively you could use InvokeRepeating, but the end result would be the same.

Feb 25 '12 at 05:49 PM OrangeLightning
(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:

x39
x5

asked: Feb 25 '12 at 04:36 PM

Seen: 513 times

Last Updated: Feb 25 '12 at 05:49 PM