Gamepad Support

Author Topic: Gamepad Support  (Read 3906 times)

Hey I got my Gamecube controller working in Blockland.


I couldn't find many resources here on the forums.  So I think this will help the next guy along.

Here’s the script I used.
Code: (base/joysticksetup2.cs) [Select]
enablejoystick();

function joyyaw(%nums)
{
$joyyaw = %nums;
}

function joypitch(%nums)
{
$joypitch = %nums;
}

function joy2yaw(%nums)
{
$joy2yaw = %nums;
}

function joy2pitch(%nums)
{
$joy2pitch = %nums;
}

function joyjump(%val)
{
jump(%val);
}

function joytogglefirstperson(%val)
{
togglefirstperson(%val);
}

function joyjet(%val)
{
jet(%val);
}

function joymousefire(%val)
{
mousefire(%val);
}

function joycrouch(%val)
{
crouch(%val);
}

function joyzoom(%val)
{
togglezoom(%val);
}

function joyusetools(%val)
{
usetools(%val);
}

function joyinvup(%val)
{
invup(%val);
}

function joyinvdown(%val)
{
invdown(%val);
}
function joylight(%val)
{
useLight(%val);
}
function joyusepaintcan(%val)
{
useSprayCan(%val);
}
function joytogglebuildmode(%val)
{
if(%val==1)
{
if($joybuildmode==1)
{
$joybuildmode = 0;
}
else
{
$joybuildmode = 1;
}
}
echo($joybuildmode);
}

$joyyaw = 0;
$joypitch = 0;
$joy2yaw = 0;
$joy2pitch = 0;
$joyjet = 0;
function joyloop(%xhist,%xhistm,%yhist,%yhistm,%shist)
{
%xhistspeed = getword(%xhist,0)+getword(%xhist,1)+getword(%xhist,2)+getword(%xhist,3)+getword(%xhist,4)+0.162;
%xhistmspeed = getword(%xhistm,0)+getword(%xhistm,1)+getword(%xhistm,2)+getword(%xhistm,3)+getword(%xhistm,4)+0.162;
%yhistspeed = getword(%yhist,0)+getword(%yhist,1)+getword(%yhist,2)+getword(%yhist,3)+getword(%yhist,4)+0.162;
%yhistmspeed = getword(%yhistm,0)+getword(%yhistm,1)+getword(%yhistm,2)+getword(%yhistm,3)+getword(%yhistm,4)+0.162;
%shistspeed = getword(%shist,0)+getword(%shist,1)+getword(%shist,2)+getword(%shist,3)+getword(%shist,4)+0.162;
%xaxis=$joyyaw;
%yaxis=$joypitch;
%rxaxis=$joy2yaw;
%ryaxis=$joy2pitch;
%slider = $joyslider;

%xspeed = %xaxis*5.4;
%yspeed = %yaxis*5.4;
%sspeed = %slider*5.4;
%xadd = (mAbs(%xspeed)*0.08)*mAbs(%yspeed);
%yadd = (mAbs(%yspeed)*0.08)*mAbs(%xspeed);
if(%xspeed>0)
{
if(%xhistspeed>mAbs(%xspeed)+%xadd)
{
if(getWord(%xhist,4)==1)
{
moveright(0);
}
%xhist = getword(%xhist,1) SPC getword(%xhist,2) SPC getword(%xhist,3) SPC getword(%xhist,4) SPC 0;
}
else
{
moveright(1);
%xhist = getword(%xhist,1) SPC getword(%xhist,2) SPC getword(%xhist,3) SPC getword(%xhist,4) SPC 1;
}
if(getWord(%xhistm,4)==1)
{
moveleft(0);
}
}
else
{
if(%xhistmspeed>mAbs(%xspeed)+%xadd)
{
if(getWord(%xhistm,4)==1)
{
moveleft(0);
}
%xhistm = getword(%xhistm,1) SPC getword(%xhistm,2) SPC getword(%xhistm,3) SPC getword(%xhistm,4) SPC 0;
}
else
{
moveleft(1);
%xhistm = getword(%xhistm,1) SPC getword(%xhistm,2) SPC getword(%xhistm,3) SPC getword(%xhistm,4) SPC 1;
}
if(getWord(%xhist,4)==1)
{
moveright(0);
}
}

if(%yspeed>0)
{
if(%yhistspeed>mAbs(%yspeed)+%yadd)
{
if(getWord(%yhist,4)==1)
{
movebackward(0);
}
%yhist = getword(%yhist,1) SPC getword(%yhist,2) SPC getword(%yhist,3) SPC getword(%yhist,4) SPC 0;
}
else
{
movebackward(1);
%yhist = getword(%yhist,1) SPC getword(%yhist,2) SPC getword(%yhist,3) SPC getword(%yhist,4) SPC 1;
}
if(getWord(%yhistm,4)==1)
{
moveforward(0);
}
}
else
{
if(%yhistmspeed>mAbs(%yspeed)+%yadd)
{
if(getWord(%yhistm,4)==1)
{
moveforward(0);
}
%yhistm = getword(%yhistm,1) SPC getword(%yhistm,2) SPC getword(%yhistm,3) SPC getword(%yhistm,4) SPC 0;
}
else
{
moveforward(1);
%yhistm = getword(%yhistm,1) SPC getword(%yhistm,2) SPC getword(%yhistm,3) SPC getword(%yhistm,4) SPC 1;
}
if(getWord(%yhist,4)==1)
{
movebackward(0);
}
}
//I have two sliders and they fight.  so i can't use em for jets.
//if(%shistspeed>mAbs(%sspeed))
//{
// if(getWord(%shist,4)==1)
// {
// jet(0);
// }
// %shist = getword(%shist,1) SPC getword(%shist,2) SPC getword(%shist,3) SPC getword(%shist,4) SPC 0;
//}
//else
//{
// jet(1);
// %shist = getword(%shist,1) SPC getword(%shist,2) SPC getword(%shist,3) SPC getword(%shist,4) SPC 1;
//}
%shist = "";

if(%rxaxis>0.08||%rxaxis<-0.08)
{
yaw(%rxaxis*20);
}
if(%ryaxis>0.08||%ryaxis<-0.08)
{
pitch(%ryaxis*20);
}
schedule(33,0,"joyloop",%xhist,%xhistm,%yhist,%yhistm,%shist);
}

if($joylooped<1)
{
$joylooped = 1;
joyloop();
}

movemap.bind(joystick0,"xaxis",joyyaw);
movemap.bind(joystick0,"yaxis",joypitch);
movemap.bind(joystick0,"zaxis",joy2yaw);
movemap.bind(joystick0,"rzaxis",joy2pitch);
movemap.bind(joystick0,"button6",joytogglefirstperson);
movemap.bind(joystick0,"button0",joyjump);
movemap.bind(joystick0,"button5",joyjet);
movemap.bind(joystick0,"button1",joymousefire);
movemap.bind(joystick0,"button4",joycrouch);
movemap.bind(joystick0,"button11",joytogglebuildmode);
movemap.bind(joystick0,"button10",joylight);
movemap.bind(joystick0,"button9",joyinvup);
movemap.bind(joystick0,"button8",joyinvdown);
movemap.bind(joystick0,"button2",joyusetools);
movemap.bind(joystick0,"button3",joyusepaintcan);
movemap.bind(joystick0,"button7",joyzoom);
//movemap.bind(joystick0,"slider",joyjet);

I had to use a loop to get the joysticks working properly.(The sticks only send information while they are actively moving.)  The problem with the loop is that it causes a TON of console spam if you run a trace with this script running.
So if anyone knows a way around using spammy loops for this I’d be very interested to know it.


These were useful:
http://legendsthegame.net/community/doku.php?id=client_setup:keybinds
http://bldocs.nullable.se/html/class_client_1_1_action_map.html
http://forum.blockland.us/index.php?topic=18143.0

Oh my GOD I love you. Trying this immediately.

You're using a USB-modded GC controller, I assume?

Tried it out with a 360 controller using xboxdrv drivers in Linux.
It works ok.
Code: [Select]
// xaxis left brown townog X
// yaxis left brown townog Y
// rxaxis right brown townog X
// ryaxis right brown townog Y
// button0 A
// button1 B
// button2 X
// button3 Y
// button4 LB
// button5 RB
// button6 back button
// button7 start button
// button8 xbox button
// button9 left brown townog button
// button10 right brown townog button
// ??? left trigger
// ??? right trigger
movemap.bind(joystick0,"xaxis",joyyaw);
movemap.bind(joystick0,"yaxis",joypitch);
movemap.bind(joystick0,"rxaxis",joy2yaw);
movemap.bind(joystick0,"ryaxis",joy2pitch);
movemap.bind(joystick0,"button6",joytogglefirstperson);
movemap.bind(joystick0,"button5",joyjump);
movemap.bind(joystick0,"button4",joyjet);
movemap.bind(joystick0,"button0",joymousefire);
movemap.bind(joystick0,"button2",joycrouch);
movemap.bind(joystick0,"button1",joytogglebuildmode);
movemap.bind(joystick0,"button3",joylight);
movemap.bind(joystick0,"upov",joyinvup);
movemap.bind(joystick0,"dpov",joyinvdown);
movemap.bind(joystick0,"lpov",joyusetools);
movemap.bind(joystick0,"rpov",joyusepaintcan);
movemap.bind(joystick0,"button10",joyzoom);

I was assuming the Z axis would be LT/RT, but nothing responded to them.

EDIT: Deadzones would be great
« Last Edit: April 17, 2014, 01:59:21 AM by TheBlackParrot »

I use a generic 3rd party Xbox 360 controller (USB) and Joystick Mapper on Mac OSX. It works perfectly for any game, but you need the driver from tattiebogle.net.

You're using a USB-modded GC controller, I assume?
Yeah. :)

I was assuming the Z axis would be LT/RT, but nothing responded to them.

EDIT: Deadzones would be great
In my setup LT would be "dial" and RT would be "slider".  But BL doesn't seem to recognize the dial bit and treats them both as a single slider.  So I can't really use either.

of course i'm ignored and whoever does almost exactly what i do gets appreciated
https://www.youtube.com/watch?v=SF8U9NzV2HU

of course i'm ignored and whoever does almost exactly what i do gets appreciated
https://www.youtube.com/watch?v=SF8U9NzV2HU
welcome to the internet

um.. maybe it's because you didn't use a gamecube controller?

of course i'm ignored and whoever does almost exactly what i do gets appreciated
https://www.youtube.com/watch?v=SF8U9NzV2HU
well ok, how'd you do yours? Joy2Key?

the advantage of this over something like joy2key or xpadder is that this can actually read the input directly from the gamepad as something other than just on/off (e.g. for sliders and joysticks that aren't buttons and would have a float value for 'how activated they are')

additionally, you can implement code to make the game control adapt better with a gamepad by making GUI and whatnot for control, which is absolutely necessary in a game like Blockland

for instance, a controller-driven brick buyer, wrench GUI, or text input method

the disadvantage is that torque's gamepad support is really goofy, but once you get around the goofiness i guess it's not an issue

My goodness this would be really fun to use. Did anyone try a PlayStation 3 controller yet?

My goodness this would be really fun to use. Did anyone try a PlayStation 3 controller yet?
Same


I made a slightly more advanced version that uses the "Start" button to switch to build mode.

Code: [Select]
LSTICK
MOVE
LT
SHIFTBRICKDOWN 1
RT
SHIFTBRICKUP 1
Z
TOGGLESUPERSHIFT
Y
ROTATEBRICKCCW
X
ROTATEBRICKCW
A
PLACEBRICK
B
UNDOBRICK
CSTICK
MOVEBRICKAWAY
MOVEBRICKRIGHT
MOVEBRICKTOWARDS
MOVEBRICKLEFT
HATU
MOVEBRICKUP 1/3
HATD
MOVEBRICKDOWN 1/3
HATL
SCROLLDOWN
HATR
SCROLLUP
START
TOGGLEBUILDCONTROLS

I tried making another version that allows for mouse movement.  But the mouse kept snapping back to its original position and I don't know enough about how the gui system works to go any further.

Soo how do i use this with an xbox or playstation controller.

Soo how do i use this with an xbox or playstation controller.
with an xbox one i assume you could just plug it in

with a playstation one probably go through DS3 tool to emulate xbox 360 controller