spaceship movement

Blitz3D Forums/Blitz3D Programming/spaceship movement

andy_mc(Posted 2004) [#1]
hi all,
I'm probably being dumb here, but what's wrong with my code? I want it to pitch, roll and yaw relative to the position of the camera, but it's not doing that...

; Space game

;player ship
Type ship
	Field y
	Field x
	Field z
	Field mx
	Field my
	Field mz
	Field myaw#
	Field yaw#
	Field mpitch#
	Field pitch#
	Field mroll#
	Field roll#
	Field fshields
	Field rshields
	Field hullstrength
	Field speed
End Type

;alien ship
Type alien
	Field y
	Field x
	Field z
	Field mx
	Field my
	Field mz
	Field yaw
	Field pitch
	Field roll
	Field fshields
	Field rshields
	Field hullstrength
	Field speed
End Type


Graphics3D 1024,768,32,1
swidth = GraphicsWidth()
sheight = GraphicsHeight()
myship = CreateSphere()
shipcamera = CreateCamera(myship)
alienship = CreateSphere()
ps.ship = New ship
PositionEntity alienship,0,0,10

SetBuffer BackBuffer()
CameraZoom shipcamera,2
While Not KeyDown(1)

Cls

If KeyDown(200) Then ps\mpitch=ps\mpitch+0.02 Mod 360
If KeyDown(208) Then ps\mpitch=ps\mpitch-0.02 Mod 360
If KeyDown(203) Then ps\mroll=ps\mroll-0.02 Mod 360
If KeyDown(205) Then ps\mroll=ps\mroll+0.02 Mod 360
ps\roll = (ps\roll + ps\mroll) Mod 360
ps\pitch = (ps\pitch + ps\mpitch) Mod 360
ps\yaw = (ps\yaw + ps\myaw) Mod 360
RotateEntity myship,ps\pitch,ps\yaw,ps\roll,True
ps\mpitch=ps\mpitch*0.99
ps\mroll=ps\mroll*0.99
ps\myaw=ps\myaw*0.99

;draw 3d
UpdateWorld()
RenderWorld()

;draw hud
;target cursor
Color 0,200,0
Line (swidth/2)-10,(sheight/2)-10,(swidth/2)-2,(sheight/2)-2
Line (swidth/2)+10,(sheight/2)-10,(swidth/2)+2,(sheight/2)-2
Line (swidth/2)-10,(sheight/2)+10,(swidth/2)-2,(sheight/2)+2
Line (swidth/2)+10,(sheight/2)+10,(swidth/2)+2,(sheight/2)+2
Flip


Wend
End



Eric(Posted 2004) [#2]
You need to Transform You rotation Vectors into Camera


TFormVector ps\roll,ps\yaw ,ps\pitch,camera,0
RotateEntity myship,TFormedX#(),TformedY#(),TFormedZ#(),True


I am playing around with a lunar Lander type Game, And I control just the Pitch and Roll with a JoyStick and I am using Code similar to the above.


andy_mc(Posted 2004) [#3]
not quite following you, if I insert the above code, everything goes weird


andy_mc(Posted 2004) [#4]
nevermind, don it now:
If KeyDown(200) Then ps\mpitch=ps\mpitch+0.02 Mod 360
If KeyDown(208) Then ps\mpitch=ps\mpitch-0.02 Mod 360
If KeyDown(203) Then ps\mroll=ps\mroll-0.02 Mod 360
If KeyDown(205) Then ps\mroll=ps\mroll+0.02 Mod 360
If KeyDown(44) Then ps\myaw = ps\myaw-0.02 Mod 360
If KeyDown(45) Then ps\myaw = ps\myaw+0.02 Mod 360

TurnEntity myship,ps\mpitch,ps\myaw,ps\mroll,False



Eric(Posted 2004) [#5]
I'm sorry, I never claim to be right, I should have taken your code and tried it. I just know that you have to transform controls to camera view, so no matter the orientation of the camera, back is back, left is left and so forth... What is your ultimate goal? I mean, I am not at my home computer right now, so I can't run your code. How is this ship supposed to fly in 3D space?


eBusiness(Posted 2004) [#6]
Ignore post please.


andy_mc(Posted 2004) [#7]
I want it to be very similar to the way you pilot ships in elite 2.


_PJ_(Posted 2004) [#8]

I want it to be similar to the way you pilot ships in elite 2


Don't we all!


I am still not 100% Satisfied with my results

http://www.blitzbasic.com/archive/posts.php?topic=17097
http://www.blitzbasic.com/archive/posts.php?topic=22092

and am perhaps about to overhaul the physics engine for Galactic Allegiance once again.