Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,449 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Inverse proportional #120545
03/31/07 19:51
03/31/07 19:51
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
Hi,

a dumb question i think, but oh well..

Imagine two points A and B and its distance = 100.

I want that when distance decreases, a variable or skill should proportional increases its value and vice versa.

An example: when distance = 80 or 100 the skill must be 20 or 0 respectively and so on.

Is there a math function to do that?
Thanks in advance

Re: Inverse proportional [Re: demiGod] #120546
03/31/07 20:07
03/31/07 20:07
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
The easiest solution I can think of:
Code:

var max_distance = 100;
var distance;
var inverse_dist;

inverse_dist = max_distance - distance;

//Examples:
distance == max_distance => inverse_dist = 0
distance = 20 => inverse_dist = 100 - 20 = 80
distance = 80 => inverse_dist = 100 - 80 = 20



Not sure if thats what you want though.

Re: Inverse proportional [Re: Xarthor] #120547
03/31/07 20:21
03/31/07 20:21
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Code:

function setDist(&PointA, &PointB, maxDist, maxVal)
{
var tDist;
tDist = vec_dist(PointA, PointB);
tDist = maxDist - clamp(tDist, 0, maxDist);
tDist /= maxDist;
return(tDist * maxVal);
}



PointA & PontB are the two vectors to check the distance between. maxDist is the range of distance the function should use for scaling. maxVal Is the maximum value that will be returned (when distance is close to 0). returns the end result.

ex:
setDist(my.x, you.x, 100, 25);

when the distance between the my & you entities is less than 100, the function will return a number between 0 (D = 100) and 25 (D = 0).


xXxGuitar511
- Programmer
Re: Inverse proportional [Re: xXxGuitar511] #120548
03/31/07 20:28
03/31/07 20:28
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
@ Thunder
Eh,eh so simple indeed it works now, thanks.

@ xXxGuitar511
I believe your function its what i was looking for because i need to define a min limit too, so thank you for your help, i will try that too.


Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1