Jump to content

XBOX 360 controller LUA template

Recommended Posts

Platform: Windows.




FPS Player scenario (Preconfigured scenario ready to play Updated 08/may/2015)



Marble game ball (Preconfigured scenario ready to play Updated 03/may/2015)



Only DLL: (Updated 08/may/2015)





- You must have connected the XBOX 360 controller to work.

- If you want put the code in you proyect, copy and paste the "LuaGamePad.dll" and "SDL2.dll" in your project folder.



New update!!

Data: 08/May2015


Working hard on my free time, I developed the LUA FPS XBOX 360 controller.


What's new:


- The movement is now analog (Left stick).

- The view is now analog (Right stick).

- The sprint is now analog (Right Trigger).

- The sound of the steps are automatically adjusted to the speed of the player, also considers the sprint.


It is fully preconfigured and is 100% functional, I've tested with the FPS Weapons Pack and works fine.


If you find a bug please send me a report.



Open the project and open the "07-AI and Events.map"


The "FPSPlayer XBOX360 controller adapted.lua" is in the same folder that "FPSPlayer.lua"

The empty template XBOX 360 controller is in the "Scrips / objects / XBOX 360 controller" folder.



Controller mapping:





Data: 03/May2015


Hello everyone!


I work hard to create a Lua XBOX 360 controller template.


(Based on the work of Skrakle).




Upgrade Author: Daniel0213


What's new:



I have expanded the functions and recompile the driver. I added:


- The right analog stick is now functional.

- The left and right trigger just happen to be digital to be analog + digital.





- The script is not oriented to App.lua, now is oriented to the object you want to control, the player. (You must insert the script on the object that you want to control).

- I created a template fully explained with comments.

- I've written and adapted the formulas needed to converter from analog value to Leadwerks. Not any knowledge of analog sensors are required to write your own program. The code gives you automatically a converted analog value.

- To change analog values you do not need to enter the code can be changed quickly from outside.

- Reduced the death zone of analogue sensors, but can be changed easily. The instruction have a comment.

- I separate all the buttons to make it easier to interpret the code.

- You can choose externally the number of controller you want to use.




I inserted the code in the template marble game, for a practical example of the operation display. Within the project it is the empty template XBOX controller and inserted into the ballplayer template for a practical example.


(I have asked permission to Josh to do this)




The empty template XBOX 360 controller is in the "Scrips / objects / XBOX 360 controller" folder.


The "ballplayer" script has been modified to insert the sample code. Changed the name to "ballplayer Adapted to XBOX 360 controller."


I'm using the Leadwerks version 3.5 Beta.








Very simple.


1. Unzip the .rar file.

2. Copy the "XBOX360controllertemplate" folder in your Leadwerks project folder.

3. Open leadwerks, go to "project manager" Push "import" enter to "XBOX360controllertemplate" folder and select the "XBOX 360 controller template.werk" file.

4. Select the project and press "OK".


You must disable the sandbox lua libraries to work xbox 360 controller.







How analog sensors work:


Put the desired maximum values.






In this case, when the left stick reaches its peak (up direction), the analog value which will be 15. Decreasing this value progressively until it reaches 0, when you reach the death zone.

Don't touch the formula.






A bit of theory: The Analog converted formula. (Don't worry, you don't have to create, it is already written in the template code.)










Future upgrades:


- Add left and right vibration.

- Linux support.




If you want put the code in you proyect, copy and paste the "LuaGamePad.dll" and "SDL2.dll" in your project folder.

Edited by Daniel0213

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...