dbox | 2007-04-18 15:47
Game Controller Support
Play sauerbraten console-style with your game controller of choice...

Just for kicks I thought I would see if I could set up game controller support for Sauerbraten. I know most serious PC gamers would never dream of giving up the mouse. Personally, I sometimes get tired of being hunched over the computer and find it relaxing to sit back on the couch and play console-style. So if you've got a pc game controller with at least one stick (preferably analog) on it you might give this a shot.

UPDATE: 04/23/2007 - Changed the joystick configuration menus to use some of sauer's new gui features (e.g. sliders, checkboxes, etc.). This makes the configuration screen a little more intuitive and reduced the number of sub-menus I needed.

The following steps will install the game controller support. The files are installed along side the existing sauerbraten files and will not affect the ability to play the unmodified original game.

  • STEP 1: Backup the data/keymap.cfg file if you want to keep the original
    (the changes are additive and will not affect the original game)
  • STEP 2: Extract this archive into your Sauerbraten directory.
  • STEP 3: Execute the sauerjoy.bat file.
  • STEP 4: Configure your controller by typing "/joymenu" in-game (without quotes)

Menu Configuration
Users can now configure game controllers using the intuitive menu-driven interface. Simply type /joymenu in-game to see the following menu:

Show Menu

From this menu you can configure all of the joystick settings. I recommend that you first set show events to yes before setting the other properties. This will cause the joystick events to be displayed in the console as buttons are pressed or axes are moved. This should help when deciding which button, pad or axis to use with each setting or action.

For any who might have been familiar with previous versions of this mod, Sauerbraten's new 3d menus have allowed me to implement some new features. There is a now a new setting, "emulate mouse", which will map a joystick button to mouse clicks. This is useful for using the game controller to select menu options, so you don't have to keep switching between mouse and game controller while you're playing.

How it works:
This section is here for those who might be interested in doing custom scripting, or interested in how the code works. If you aren't interested in this, you might just want to skip down to the Disclaimer section.
Basically, I took the approach that I would intercept joystick events and translate them into sauerbraten keypress events. This allows joystick events to be "bound" to actions like you would any other keyboard or mouse event.

Config File Settings
The following new variables have been defined to configure the joystick. Once set, they will be automatically placed in the autoexec.cfg. The joystick can be completely configured using the dynamic menus.

joyfovxaxis / joyfovyaxis
This setting specifies which stick should control the field of view (what the mouse does for you now). Each stick has a horizontal and a vertical axis. Each axis is numbered starting with 1. So, for example, on my controller, which is very similar to the one pictured above, if I wanted the use the left stick the settings would be:

joyfovxaxis 1
joyfovyaxis 2


joyfovxaxis 2
joyfovyaxis 1

depending on how your controller numbers the axes.

If you wanted to use the right one (recommended) the settings would be:

joyfovxaxis 3
joyfovyaxis 4


joyfovxaxis 3
joyfovyaxis 4

Specifies how the stick controls your field of view. If set to 0 you will look in the direction you press on the stick. If set to 1 (inverted) the control works like a flight simulator: pull back on the stick to nose up, push forward to nose down. This is the default.

This property sets up the minimum amount of movement that is required to trigger an event when binding axis movements to actions. The range for this setting is 1-30. If set to 1 you basically just have to breath hard on the stick and it will trigger the event. If set to 30 you'll have to push it practically to the edge. The default is 8.

This is the property you'll probably end up tweaking the most. On certain maps where you're getting really low fps you might need to bump this up a bit. The range for this setting is 1-10 where 1 is the least sensitive and 10 is the most. Remember, these values can be set from within the game. Just type /joysensitivity n at the console to bump the sensitivity up or down, or better yet, create an alias and map this to a couple of your joystick buttons. (See the response below titled "Joystick Sensitivity Script" for an example of how to do this.)

This property is meant to be used when configuring your game controller. When joyshowevents is set to 1, all joystick events will be displayed in the console. This will help you determine which button to use when binding actions to the joystick, as well as which axis to use for movement and field of view control.

For example, if you want to use a certain button to fire your gun, press that button and you will see something like this displayed in the console:


You can then bind that button from within the game by typing:

/bind JOYBUTTON7 [attack]

(Binding joystick events is discussed further in the next section.)

This is also useful for configuring the field of view axis. In this case you just move the axis to the left and right and then up and down. This will display which axes are being moved which you can use to set the joyfovxaxis and joyfovyaxis values.

Binding Joystick Events
There are currently three types of joystick events you can bind to actions:

Binding Buttons
I've left space for up to 20 joystick buttons that can be bound to the action of your choice. For example, I wanted to map "attack/shoot" to my right trigger finger button, and "jump" to the trigger finger on the left. On my controller the right trigger button is button 8 and the left trigger button is button 7, so I added the following lines to my autoexec.cfg file:

bind "JOYBUTTON8" [attack]
bind "JOYBUTTON7" [jump]

Binding Stick Movements
I've left space for up to 5 sticks (10 total axes) that can be bound to actions. I wanted to use the left stick to control my movement: push forward on the stick to move forward, back to move backward, right and left to strafe. So, I added the following lines:

bind "JOYAXIS1MIN" [left]
bind "JOYAXIS1MAX" [right]
bind "JOYAXIS2MIN" [forward]
bind "JOYAXIS2MAX" [backward]

Binding Pad Movements
Some controllers, like the one in the picture above, have those little up/down/left/right "pad" or "hat" controls. In the picture above I have up mapped to zoom-in and down mapped to zoom-out. The binding for that would look like this:

bind "JOYHAT1NORTH" [fov 15; crosshairsize 50]
bind "JOYHAT1SOUTH" [fov 110; crosshairsize 22]

You could also use that pad for controlling your movement. That would look like this:

bind "JOYHAT1NORTH" [forward]
bind "JOYHAT1NE" [forward; right]
bind "JOYHAT1EAST" [right]
bind "JOYHAT1SE" [backward; right]
bind "JOYHAT1SOUTH" [backward]
bind "JOYHAT1SW" [backward; left]
bind "JOYHAT1WEST" [left]
bind "JOYHAT1NW" [forward; left]


  • This is built from the 2007-04-13 spring edition of Sauerbraten.
  • This works for all(2) of my controllers. I do not know if it will work for you. (Please try it out and let me know.)
  • If your game controller does not have at least one stick, this will not work.
  • This supports only one game controller. If you have more than one connected, I'm just going to take the first one I find.
  • If no game controller is recognized, or the game controller cannot be initialized for whatever reason there will be no notification, sauerbraten will just load as normal.
  • I have not tried this on linux yet.
  • Note to Cube Players: I have discontinued including updates for the Cube code and executables. You can still get it here. If there was enough interest in the Cube/ActionCube community, I would consider continuing Cube support.

Let me know what you think. I would appreciate any and all feedback.

- dbox

sauerjoy.zip (264.16 KB)
 (0 votes)
User login
Users on Quadropolis
2 guests & no users online
Created 2022-01-23 15:48
8 hours 41 min ago
Created 2021-11-05 01:27
11 weeks 2 days ago
points ]
 (4 votes)
Created 2020-12-10 12:49
1 year 6 weeks ago
points ]
 (4 votes)
Created 2012-08-30 04:30
9 years 21 weeks ago
points ]
 (1 vote)
Created 2019-10-16 01:26
2 years 14 weeks ago
points ]
 (1 vote)
Created 2021-06-17 22:42
31 weeks 3 days ago
points ]
 (3 votes)
Created 2020-11-30 04:00
1 year 7 weeks ago
points ]
 (1 vote)
Created 2021-05-24 00:01
35 weeks 27 min ago
points ]
 (10 votes)
Created 2019-12-05 20:57
2 years 7 weeks ago
points ]
 (2 votes)
Created 2020-12-20 03:04
1 year 4 weeks ago
points ]
 (3 votes)
Created 2020-12-04 12:05
1 year 7 weeks ago
points ]
 (2 votes)
Created 2020-12-03 17:12
1 year 7 weeks ago
points ]
 (3 votes)
Created 2020-06-13 21:05
1 year 32 weeks ago
points ]
 (6 votes)
Created 2020-01-23 12:57
2 years 1 day ago
points ]
 (8 votes)
Created 2020-10-11 13:46
1 year 14 weeks ago
points ]
 (7 votes)
Created 2018-12-04 15:12
3 years 7 weeks ago
points ]
 (4 votes)
Created 2020-10-22 00:50
1 year 13 weeks ago
points ]
 (2 votes)
Created 2020-11-22 21:21
1 year 8 weeks ago
points ]
 (4 votes)
Created 2020-11-18 21:08
1 year 9 weeks ago
points ]
 (3 votes)
Created 2020-11-15 18:16
1 year 9 weeks ago
Who's new
  • letic86
  • WASP
  • Im_Percynator
  • micai