What it sounds like you’re asking for is to “interpret the output from the SSK2 joystick as Cardinal+”.
I define Cardinal as:
- N - 0-degrees
- W - 90-degrees
- S - 180-degrees
- E - 270-degrees
Cardinal + simply adds four additional directions NW, SW, SE, NE to this.
So, how would I go about implementing this system using SSK2’s joystick? Like this…
local player = ... code to make player object. function player.doNorth( self ) -- Code to handle moving north or whatever .... end function player.doNorthWest( self ) -- Code to handle moving north-west or whatever .... end ... etc.
Now create a custom joystick listener on the player object:
function player.onJoystick( self, event ) local angle = event.angle local offset = 22.5 if( angle \<= offset ) then self:doNorth() elseif( angle \> offset and angle \<= 45 + offset ) then self:doNorthWest() elseif( angle \> 45 + offset and angle \<= 90 + offset ) then self:doWest() elseif( angle \> 90 + offset and angle \<= 135 + offset ) then self:doSouthEast() elseif( angle \> 135 + offset and angle \<= 180 + offset ) then self:doSouth() elseif( angle \> 180 + offset and angle \<= 225 + offset ) then self:doSouthWest() elseif( angle \> 225 + offset and angle \<= 270 + offset ) then self:doWest() elseif( angle \> 270 + offset and angle \<= 315 + offset ) then self:doNorthEast() elseif( angle \> 315 + offset ) then self:doNorth() end end; listen( "onJoystick", player )
Note 1: You do not need the doNorth(), noEast(), etc. functions. I just presented it this way because that is a cleaner way to code and demo it.
Note 2: To any readers who don’t agree with the angles, this is based on how SSK2’s angles work, not the traditional Cartesian values you were taught in school.