This is an old example I made for someone else ages ago, I didn't over comment it but I hope its easy to follow:
Set Display Mode Desktop Width(), Desktop Height(), 32, 1
Sync On : Set Window Off
Autocam Off
` Vector to hold the inertia speed
Type Vector3D
X as Float
Y as Float
Z as Float
EndType
` Spaceship Description UDT
Type SpaceshipDesc
o as Integer
Inertia as Vector3D
Acceleration as Float
EndType
` Create a spaceship
Global Spaceship as SpaceshipDesc
Spaceship.o = 1
Spaceship.Acceleration = .005
Spaceship.Inertia.X = 0.0
Spaceship.Inertia.Y = 0.0
Spaceship.Inertia.Z = 0.0
Make Object Box Spaceship.o, .5, .25, 1.0
Position Object Spaceship.o, 0.0, 1.0, 0.0
` Create a dummy object to get the forward vector
Global DUMMY as Integer = 999
Make Object Plain DUMMY, 1.0, 1.0
Hide Object DUMMY
` Create the ground
Global Ground as Integer = 2
Make Object Plain Ground, 20.0, 20.0
Position Object Ground, 0.0, 0.0, 0.0
XRotate Object Ground, 90
` Position the camera
Position Camera 0.0, 20.0, 0.0
Point Camera 0.0, 0.0, 0.0
` Main Loop
Do
` Control the spaceships rotation
If LeftKey() then Turn Object Left Spaceship.o, 5.0
If RightKey() then Turn Object Right Spaceship.o, 5.0
` If the W key is pressed, move the ship forward
If Keystate( 17 )
` Get the dummy object and use it to calculate the forward vector
Position Object DUMMY, 0, 0, 0
Set Object To Object Orientation DUMMY, Spaceship.o
Move Object DUMMY, 1.0
` Multiply the distance value by the acceleration and add to the inertia
Spaceship.Inertia.X = Spaceship.Inertia.X + Object Position X( DUMMY ) * Spaceship.Acceleration
Spaceship.Inertia.Y = Spaceship.Inertia.Y + Object Position Y( DUMMY ) * Spaceship.Acceleration
Spaceship.Inertia.Z = Spaceship.Inertia.Z + Object Position Z( DUMMY ) * Spaceship.Acceleration
EndIf
` If the S key is pressed, move the ship backward
If Keystate( 31 )
` Get the dummy object and use it to calculate the backward vector
Position Object DUMMY, 0, 0, 0
Set Object To Object Orientation DUMMY, Spaceship.o
Move Object DUMMY, -1.0
` Multiply the distance value by the acceleration and add to the inertia
Spaceship.Inertia.X = Spaceship.Inertia.X + Object Position X( DUMMY ) * Spaceship.Acceleration
Spaceship.Inertia.Y = Spaceship.Inertia.Y + Object Position Y( DUMMY ) * Spaceship.Acceleration
Spaceship.Inertia.Z = Spaceship.Inertia.Z + Object Position Z( DUMMY ) * Spaceship.Acceleration
EndIf
` If the D key is pressed, strafe the ship right
If Keystate( 32 )
` Get the dummy object and use it to calculate the right vector
Position Object DUMMY, 0, 0, 0
Set Object To Object Orientation DUMMY, Spaceship.o
Move Object Right DUMMY, 1.0
` Multiply the distance value by the acceleration and add to the inertia
Spaceship.Inertia.X = Spaceship.Inertia.X + Object Position X( DUMMY ) * Spaceship.Acceleration
Spaceship.Inertia.Y = Spaceship.Inertia.Y + Object Position Y( DUMMY ) * Spaceship.Acceleration
Spaceship.Inertia.Z = Spaceship.Inertia.Z + Object Position Z( DUMMY ) * Spaceship.Acceleration
EndIf
` If the A key is pressed, strafe the ship left
If Keystate( 30 )
` Get the dummy object and use it to calculate the left vector
Position Object DUMMY, 0, 0, 0
Set Object To Object Orientation DUMMY, Spaceship.o
Move Object Left DUMMY, 1.0
` Multiply the distance value by the acceleration and add to the inertia
Spaceship.Inertia.X = Spaceship.Inertia.X + Object Position X( DUMMY ) * Spaceship.Acceleration
Spaceship.Inertia.Y = Spaceship.Inertia.Y + Object Position Y( DUMMY ) * Spaceship.Acceleration
Spaceship.Inertia.Z = Spaceship.Inertia.Z + Object Position Z( DUMMY ) * Spaceship.Acceleration
EndIf
`Same code for the other directions, but make sure the move object command is correct, like to strafe upwards, its Move Object Up DUMMY, 1.0
` Update the spaceships position
Position Object Spaceship.o, Object Position X( Spaceship.o ) + Spaceship.Inertia.X, Object Position Y( Spaceship.o ) + Spaceship.Inertia.Y, Object Position Z( Spaceship.o ) + Spaceship.Inertia.Z
Sync
Loop
This code will work regardless of how you rotate the object, so you can use the Turn, Pitch and Roll commands with it.