Maths Question - Is There An Easier Answer.

Blitz3D Forums/Blitz3D Beginners Area/Maths Question - Is There An Easier Answer.

Maximus Primal(Posted 2005) [#1]
Sorry. My maths is really poor these days.

I need to convert a negative number into it's positive version for use as a speed control on an analog joystick.

I am currently using this:

	percent1#=JoyZ()
	percent2#=1+percent1#
	percent1#=1-percent2#
	max_speed=top_speed*percent1


Is there an easier way of making a negative number positive. My method works but something tells me you can do it in one equation and not two as I am. I know this might sound like nitpicking but silly things like this annoy me at times.

Max


BlitzSupport(Posted 2005) [#2]
Use Abs (value).


Who was John Galt?(Posted 2005) [#3]
or if you know percent 1 is -ve in the first place, use -percent1


Andy(Posted 2005) [#4]
If you need to reverse a direction, say from -50 to +50 or +50 to -50, then just multiply by -1.

ANdy


Maximus Primal(Posted 2005) [#5]
Wow good selection of answers! :) Thanks a lot guys.

Time to play a little...

Max

Just changed it to:

	max_speed=top_speed*(Abs(JoyZ()))


Now that looks a LOT nicer. And I can follow it too! :)

Thanks again.


Shagwana(Posted 2005) [#6]
if you know a number is negative you can do
num=0-num

to make it posative


Bot Builder(Posted 2005) [#7]
or just num=-num, slenkar :)


Maximus Primal(Posted 2005) [#8]
num=-num? THAT simple? Damm. Oh well I will stick with what I have. Didn't realise that such a simple maths question had so many solutions...

Max


DH(Posted 2005) [#9]
Sorry. My maths is really poor these days.

Lucky for you functions exist that for this type of thing eh :-)