Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Newbie Questions
by AndrewAMD. 12/04/23 11:14
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (TipmyPip, izorro), 556 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 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