Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Akow, TipmyPip, tomaslolo), 788 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 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 | chip programmers | 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