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

You must understand the Game Editor concepts, before post here.

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

Postby Hblade » Wed Nov 24, 2010 4:13 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

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

Postby 157pl » Sat Nov 27, 2010 5:19 pm

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;
User avatar
157pl
 
Posts: 109
Joined: Thu May 13, 2010 10:49 pm
Location: AZ
Score: 3 Give a positive score

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

Postby Hblade » Mon Nov 29, 2010 12:56 pm

Ah, pure genius :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

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

Postby Game A Gogo » Sat Dec 04, 2010 3:34 pm

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.
Last edited by Game A Gogo on Sat Dec 04, 2010 3:37 pm, edited 1 time in total.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

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

Postby Hblade » Sat Dec 04, 2010 3:37 pm

lol nah :3 weird though but it doesnt :o
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron