rotating based on joystick

Blitz3D Forums/Blitz3D Programming/rotating based on joystick

ryan scott(Posted 2005) [#1]
i'm unsure how to make this work. if the player moves the second joystick (represented by joyroll() for leftright and joyz() for updown) i want to translate that into the rotateentity that's correct for pointing the turret in that direction. move it upper left, turret should rotate to upper left.

i am clueless about how to do the math for this.

can anyone help?

i think i need some trig! but don't know what exactly. :(

(ps its a robotron style controlled game - one joystick for move, the other for shooting direction)


ryan scott(Posted 2005) [#2]
answering my own question... it was easy

If Abs(JoyRoll())>20 Or Abs(JoyZ())>.2
PositionEntity crosshair,JoyRoll(),.8,-JoyZ()*180 ; relative to parent
PointEntity turret,crosshair
EndIf

this is hard coded for my particular joystick at the moment - 2nd stick is JoyRoll for x, JoyZ for y, but JoyRoll goes -180 to 180 with about 20 that needs to remain dead, and JoyZ goes from -1 to 1.

turret and crosshair are parented to my player object. i just move crosshair to wherever joystick points from player object and then aim turret at it. crosshair is not visible in my case