Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Math question pretty "Basic"

Brasou Kwasman
Registered User
Join date: 12 May 2008
Posts: 15
06-14-2008 15:04
Wow, I can beleiver I cant figure this out, But pretty much heres what I want to do, I want to be able to push an object base on its distance from another object, using some key variables

float DISTANCE_FULL_PULL=5;
float DISTANCE_ZERO_PULL=4;

So pretty much, if Distance is 4 or less, the push is 0.0
if distance is >=5, then the push is 1.0

The main problem im having is the inbetween part, I know its pretty simple its just a 2d line(Pretty much)

m=rise/run
Y=mx+b

m=1/DISTANCE_FULL_PULL-DISTANCE_ZERO_PULL
Push=(m*distance)+DISTANCE_ZERO_PULL

is that correct? I dont have any real way of testing it, but it seems to work
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-14-2008 16:30
I think what you essentially want is just:

CODE

float DISTANCE_FULL_PULL = 5.0;
float DISTANCE_ZERO_PULL = 4.0;

float push = (distance-DISTANCE_ZERO_PULL)/(DISTANCE_FULL_PULL-DISTANCE_ZERO_PULL);
if (push < 0.0)
{
push = 0.0;
} else if (push > 1.0)
{
push = 1.0;
}