BlitzODE and Joystick

Blitz3D Forums/Blitz3D Userlibs/BlitzODE and Joystick

jeffmorris(Posted 2006) [#1]
I tried to modify the Blitz-ODE Car Demo program so that I can use a joystick (actually steering wheel/pedals) to control the car. In the original program, if you press the down arrow key while the car is moving forwards, the car slows to a stop and then moves backwards. Pressing the space bar stops the car. In my modified program, pressing the gas pedal moves the car forward, pressing the brake pedal slows the car to a stop and then the car moves backwards. Pressing a button just behind the steering wheel stops the car. I wish to modify the program so that the gear shifter allows the car to move forwards and backwards using the gas pedal and so that the brake pedal slows down the car and stops the car. I wish to modify the code for steering the car so that the more that I turn the steering wheel, the more that the front wheels steer to left or right. Here is part of the code:

Function UpdateKeys()
If JoyY(1) < -0.1
	Speed=Speed+0.1
	If Speed>30 Then Speed=30
End If
If JoyY(1) > 0.1
	Speed=Speed-0.1
	If Speed<-10 Then Speed=-10
	If Speed>0 Then Speed=Speed*0.97
End If
If JoyY(1) > -0.1 And JoyY(1) < 0.1 Then Speed=Speed*0.99
If JoyX(1) < -0.1
    Steer=Steer+0.05
    If Steer>0.5 Then Steer=0.5
End If
If JoyX(1) > 0.1
    Steer=Steer-0.05
    If Steer<-0.5 Then Steer=-0.5
End If
If JoyX(1) > -0.1 And JoyX(1) < 0.1 Then Steer=0
If JoyHit(5,1)=1
	Speed=0
	ODE_dBodySetRotation(Car,0,0,0)
End If
End Function


Is it possible for me to replace the blue box with a car body that I will create?


jeffmorris(Posted 2006) [#2]
I think that I got the code working but steering is still tricky. I was able to create car body.

Function UpdateKeys()
	If JoyHit(13,1) Then gear=gear-1:If gear<-1 Then gear=-1
	If JoyHit(14,1) Then gear=gear+1:If gear>1 Then gear=1
	If gear=-1 Then gearstring="Reverse"
	If gear=0 Then gearstring="Neutral"
	If gear=1 Then gearstring="Drive"
	If JoyY(1) < -0.1
		If gear=1
	  		Speed=Speed+0.1
	  		If Speed>30 Then Speed=30
		End If
		If gear=-1
	  		Speed=Speed-0.1
      		If Speed<-10 Then Speed=-10
		EndIf
	End If
	If JoyY(1) > 0.1
		Speed=Speed-0.2
		If Speed<0 Then Speed=0
		If Speed>0 Then Speed=Speed*0.97
	End If
	If JoyY(1) > -0.1 And JoyY(1) < 0.1 Then Speed=Speed*0.99
	If JoyX(1) < -0.1
    	steer=-JoyX(1)
    	If Steer>0.5 Then Steer=0.5
	End If
	If JoyX(1) > 0.1
    	steer=-JoyX(1)
    	If Steer<-0.5 Then Steer=-0.5
	End If
	If JoyX(1) > -0.1 And JoyX(1) < 0.1 Then Steer=0
	If JoyHit(5,1)=1
		Speed=0
		dBodySetRotation(Car,0,0,0)
	End If
End Function