Xbox One Controller Camera Script - Arsenal RSL

Hey everyone!

I’ve written a camera script for the BGE that uses the Xbox One Controller! Make sure that the camera object is parented to your ‘player’ object in order for this to work. The main objective of the script is to rotate the player left/right and for the camera to rotate up/down using the “RIGHT THUMBSTICK” on your ‘Xbox One’ controller.

PLEASE NOTE! THE CODE BELOW HAS BEEN MODIFIED TO WORK MORE EFFICIENTLY THAN THE CODE IN THE VIDEO!

Be sure to subscribe to my YouTube channel for more tutorials!

Arsenal RSL
https://www.youtube.com/channel/UC8fEnP9462piEg4xa3xNHOA

Initial Xbox One/Camera Script Tutorial:

BGE Python Playlists:

import bge

def main():

cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()

player = scene.objects [“player”]

sticks = bge.logic.joysticks

controller = sticks[0]

#print(controller.axisValues)

values = controller.axisValues

rightStickHorizontal = values[3]
rightStickVertical = values[4]

absolute values of joysticks determine how far off the joysticks are moved.

absHorizontal = abs(rightStickHorizontal)
absVertical = abs(rightStickVertical)

calculates the absolute value of the joystick to determine movement

enables player/camera to not move if joystick is ‘slightly positioned’ in a certain direction

if absHorizontal < 0.25:
rightStickHorizontal = 0.0

if absVertical < 0.25:
rightStickVertical = 0.0

rotates player (z axis) and camera (x axis)

player.applyRotation([0, 0, rightStickHorizontal * -0.03],True)
own.applyRotation([rightStickVertical * -0.03, 0, 0], True)

main()