HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Inverse proportion

11-14-2003, 01:48 AM#1
Eriond
I use the function Distance between points. I've got the two points. How do I make it so a unit loses life in relation to the point? The closer you are, the more damage you get. The only problem is that, I can seem to only get the reverse, where you get more damage, the farther away you are. It's on the tip of my brain, I just can't get it :bgrun: .

Unit - Set life of (Picked unit) to Life of (Picked Unit) - ((Distance between (Position of (Picked unit)) and Volcano) / 100.00)

That's the distance thing. But I want it to work inversely! How do I do it!?
11-14-2003, 02:04 AM#2
FerretDruid
((Distance between (Position of (Picked unit)) and Volcano) / .01)

?
11-14-2003, 02:05 AM#3
Thunder-Hunter
maybe try distance volcano thingy /-100? Not sure if it will work but give it a shot.

Rawr Ferret Druid posted same time.
11-14-2003, 02:08 AM#4
Eriond
God damnit! I knew that. Thanks Ferret. You too thunder, for trying. I owe you both one.

EDIT: WAIIIIIT a minute. That doesn't work, it's the same thing as multiplying.... I knew there was a reason why my forge kept blowing up instantly.... I'm not thinking too clearly tonight. Ok, any other ideas?
11-14-2003, 02:17 AM#5
Eriond
Erm sorry to post again, but I fear you will all think the problem is solved, if my post is just edited you might miss it.... please continue nathanmx....
11-14-2003, 03:46 AM#6
Ligature
a couple functions of x that decrease as x increases:

N - x

N / x
11-14-2003, 05:00 AM#7
Eriond
Divided, No,

EX: 2/2 = 1, 4/2 = 2
- Won't work because 1 - 100 = -99, 200-100=100

.... Are you sure you understand the question?

Anyway, there has to be some math function that'll reverse this...
11-14-2003, 05:34 AM#8
Lost Loch
How's this strike you? (Current HP - (Max Distance from Volcano - Distance of Unit from Volcano)/Some Constant like 100)

The key is to subtract the distance from another value. (which must not be less than the furthest you can be from the volcano or it'll start healing people) I'm sure there's some crazy, obvious metaphor I could make to explain this, but hopefully it makes sense on its own. (Think about it... at the max distance, it would be (Max - Max), which is 0... at no distance, it would be (Max - 0) which should be the largest it can get.)
11-14-2003, 05:34 AM#9
Karma Patrol
set the life percentage to 1/DistanceFunc()
11-14-2003, 03:17 PM#10
Newhydra
let x = Distance of unit from volcano

Now getting the inverse is rather easy :P
1/x...Either divide 1 by x directly or raise x to -1...

Of course, this assumes that you'll never be the volcano. To make sure of this have an if statement before this function which says " If <distance> is greater than <min distance> and less than <max distance> then do the damage stuff, else do nothing"
Where <min distance> is some constant number to make sure you don't divide by 0 (say, .1) and <max distance> is the maximum distance away from the volcano that you want to take damage.

So the entire damage thing would look like this:
real x = (Distance between (Position of (Picked unit)) and Volcano) -Just to make it easy...replace all x with that function if you have to

if ( x > 0.1 and x < <maximum distance> )
then
Unit - Set life of (Picked unit) to Life of (Picked-Unit) - ( 1 / x ) * <some constant if dmg is too high/low> )
else if ( x < or equal to 0.1 )
Kill Picked unit --The unit got too close to the volcano
else
--Do nothing, the unit is too far away to take damage



Technetium-> %s will not work because if the unit moved towards the volcano and then away from it, the unit would heal...
11-14-2003, 04:17 PM#11
Lost Loch
Hmmmm... you know, that works, NewHydra! (Well, OK, obviously you knew it worked or else you wouldn't have posted, but...)

Actually, this brings up an interesting point, because both my and NewHydra's answers will give increasing damage at closer distances from the volcano, but the results will not be identical. For the purposes of this example, let's assume the damage-correction multiplier thingy (the 100 in the original equation) is just 1 so we can ignore it.

Consider: In mine, if you move 1 further away from the volcano, you take 1 less damage. In Hydra's, if you move 1 further away from the volcano, you may take differring amounts less damage depending on where you were to begin with. If you were originally 1 from the volcano, then you were originally taking 1/1 or 1 damage. Moving 1 away makes it 1/2 or .5 damage. You just halved your damage. But if you were at 100 away from the volcano, you were taking 1/100 damage, but after moving you are only taking 1/101 damage... barely different. (Ignore, for a moment, the fact that these are miniscule numbers... the multiplier we are ignoring can handle it.)

To get really technical, my equation is a linear scale whereas Hydra's is logarithmic.

If I just lost you, basically under the equation I proposed, you always take the same amount of damage less for moving the same distance away. Moving 1 away is 1 less damage in any case. With Hydra's system, the closer you are to the volcano, the more the damage lowers with each step away from it. When very near the volcano, a few units will make a huge different, but far away, you could run across the screen and not notice.

There's nothing inherently more right or wrong about either system, it's just a matter of which effect you want your players to suffer in your map. :gsmile:

Incidentally, although Technetium's idea does not work for this situation, it does have interesting applications in other places... I wonder where I could use a system where being closer to the center meant more HP. *trails off mumbling about potential energy and pathfinding*
11-14-2003, 05:37 PM#12
Ligature
I think you misunderstood - when I said "N/x or N - x," I meant x is the distance from the epicenter and N is some constant...

This means you'll need some maximum or minimum either way, because N - x will probably go negative at some point and you probably want it to bottom out at zero; meanwhile N/x will skyrocket the closer you get to x = zero...
11-14-2003, 06:37 PM#13
Eriond
Thanks guys, I can't belive I didn't get the dividing thing figured out.... could've had something to do with the fact I was up at like 2 AM..... oh well. Thanks all. Here's the new trigger in all it's glory. Seems to work well for everything within 8000 radius. Deals this much damage every .10 seconds.

Unit Group - Pick every unit in (Units in (Entire map)) and do (Actions)
Loop - Actions
Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - (8000.00 / (Distance between (Position of (Picked unit)) and Volcano)))
11-14-2003, 08:15 PM#14
Lost Loch
Ah, well in that case Ligature had Hydra and me both beat to the punch, we just didn't realize it. ;) Anyway, glad the problem's solved!