Cursor for Xbox Controller

How to make an onscreen cursor controlled by your xbox controller

Created: 14 Mar 2014
Creator: Anaveragerecon
Length: 10:17
Level: Advanced
Type: Koding skills


Here is the kode used in this video. It allows you to move a cursor around the screen with an xbox controller. You can use this method to make point and click, hidden object games, inventory systems or puzzle elements.

In a logic cube (Cursor kode)

  1. WHEN DO [forward][equals][north]
  2. WHEN [countdown timer][5][in frames]
  3. …WHEN [once] DO [vectorvar:origin][equals][position]
  4. WHEN [left stick] DO [move][at speed][0.18][with strafing][object relative]
  5. WHEN [position][z][greater than or equal to][vectorvar:origin][z][plus][1] DO [position][z][equals][vectorvar:origin][z][plus][1]
  6. WHEN [position][z][less than or equal to][vectorvar:origin][z][minus][1] DO [position][z][equals][vectorvar:origin][z][minus][1]
  7. WHEN [position][x][greater than or equal to][vectorvar:origin][x][plus][1] DO [position][x][equals][vectorvar:origin][x][plus][1]
  8. WHEN [position][x][less than or equal to][vectorvar:origin][x][minus][1] DO [position][x][equals][vectorvar:origin][x][minus][1]
  9. WHEN DO [global][vectorvar:mouse position][x][equals][position][x][minus][vectorvar:origin][x]
  10. WHEN DO [global][vectorvar:mouse position][y][equals][position][z][minus][vectorvar:origin][z]
  11. WHEN DO [display][icon:small circle][at screen position][global][vectorvar:mouse position]

To select objects on the screen with the cursor (not in this video)

You can also select objects in the 3d world with this method if you lock off the camera, and determine the position of the object as it appears in the 2d.

In a logic cube

page 1 @detect object on screen

  1. WHEN DO [call page][page: @vectors]
  2. WHEN DO [call page][page: @display]
    Do this for every object you want to detect on the screen. Watch for the indents.
  3. WHEN [global][vectorvar:mouse position][x][greater than][vectorvar:object1][x][minus][0.05]
  4. …WHEN [else] DO [boolvar:object 1][equals][false]
  5. …WHEN [global][vectorvar:mouse position][x][less than][vectorvar:object1][x][plus][0.05]
  6. …/…WHEN [else] DO [boolvar:object 1][equals][false]
  7. …/…WHEN [global][vectorvar:mouse position][y][greater than][vectorvar:object1][y][minus][0.05]
  8. …/…/…WHEN [else] DO [boolvar:object 1][equals][false]
  9. …/…/…WHEN [global][vectorvar:mouse position][y][less than][vectorvar:object1][y][plus][0.05] DO [boolvar:object 1][equals][true]
  10. …/…/…/…WHEN [else] DO [boolvar:object 1][equals][false]

page 2 @vectors

Do this to place each object on the screen
The east number is the x coordinate, the world up number is the y coordinate. The center of the screen is 0,0, far right is 0,1, far left is 0,-1, top is 1,0, bottom is -1.0

  1. WHEN DO [vectorvar:object1][equals][east][multiplied by][0.5][plus][world up][multiplied by][0.6]

page 3 @display

Do this for each object

  1. WHEN [boolvar:object 1] DO [display][icon:object][color:blue][scale][0.3][at screen position][vectorvar:object 1] / change the opacity, size or color of the display object to show it is selected, or change the icon entirely
  2. …WHEN [else] DO [display][icon:object][scale][0.3][at screen position][vectorvar:object 1] // how it will display normally
  3. …WHEN [button:A][pressed] DO …..add kode for what happens if you press A when the object is selected.


Comments are closed.

Powered by

Up ↑

%d bloggers like this: