Page 1 of 1

How-To: Get the right speed you want with joysticks :D

PostPosted: Wed Nov 24, 2010 4:13 pm
by Hblade
Hey guys :D This is a simple method of getting the right speed / velocity you want the player to move with using the controller! :D

First, make a text actor and call him"TEST". Then, go to draw actor and put this code in:
Code: Select all
float ls_XAxis = GetJoystick1Axis(0);
textNumber = ls_XAxis;


This will reveal the max X speed you can go with the joystick. My max results were "32768", so I open up the calculator, and type in that number, "32768" then I devide it by how much velocity I want. For example, if I want an xvelocity of "5", I'd divide it by 5.

The results:
32768 / 5 = 6553.6

So now, go to the player you want to have moving with the joystick, and put this code in (After you already put the Xaxis and Yaxis scripts in, find them here)

Use this code in the draw actor of the player or what ever actor your trying to move with the joystick
Code: Select all
xvelocity = ls_XAxis / 6553.6

And now your player will always be moving at an xvelocity of 5 :D

You must do the same with the yspeed

Re: How-To: Get the right speed you want with joysticks :D

PostPosted: Sat Nov 27, 2010 5:19 pm
by 157pl
but you could make it work with any joystick by deviding it in the code right
like this
Code: Select all
xvelocity = ls_XAxis / (ls_XAxis = GetJoystick1Axis(0))/5;

Re: How-To: Get the right speed you want with joysticks :D

PostPosted: Mon Nov 29, 2010 12:56 pm
by Hblade
Ah, pure genius :D

Re: How-To: Get the right speed you want with joysticks :D

PostPosted: Sat Dec 04, 2010 3:34 pm
by Game A Gogo
somehow I sense an "Illegal division by zero" there

and on another note, ALL joysticks goes from -32767 to 32768, on both axis, and if you have a button pad, it works the same.

Re: How-To: Get the right speed you want with joysticks :D

PostPosted: Sat Dec 04, 2010 3:37 pm
by Hblade
lol nah :3 weird though but it doesnt :o