Knocked up this crude flight system for a game idea. It could definitely be improved on. Especially when you try to turn a 360 and the plane kicks back the other way.
Throw a plane model in there and give it a testing.
Mousewheel controls airspeed btw.
Throw a plane model in there and give it a testing.
Mousewheel controls airspeed btw.
;Mouse Flight System ; by Chroma Graphics3D 1024,768,32,2 SetBuffer BackBuffer() ;Set up camera camera = CreateCamera() CameraRange camera,1,50000 CameraClsColor camera,149,190,245 PositionEntity camera,0,5,-50 light = CreateLight() ;Make some ground ground = CreatePlane() EntityColor ground,100,50,50 ;Hide the mouse pointer HidePointer ;Place randome cubes on the ground for reference For a = 1 To 500 PositionEntity CreateCube(),Rand(-500,500),.5,Rand(-500,500) Next ;Plane Angle Parameters Max_Pitch# = 55 Yaw_Rate# = 1 plane = LoadMesh("plane.3ds") PositionEntity plane,0,20,0 ;set mouse to middle of the screen MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 ;create fake camera pivot campivot = CreatePivot() EntityParent camera,campivot ;set fake delta time Global dt#=.016 ;Main Loop While Not KeyHit(1) Cls ;Get 2d coords of the plane CameraProject camera,EntityX(plane,True),EntityY(plane,True),EntityZ(plane,True) pitch# = (MouseY()-ProjectedY()) / (GraphicsHeight()/2) * Max_Pitch yaw# = yaw + -(MouseX()-ProjectedX()) / (GraphicsWidth()/2) * Yaw_Rate# RotateEntity plane,pitch,yaw,0 ;Throttle airspeed# = MouseZ() * 0.1 If airspeed < 0 Then airspeed = 0 If airspeed >1 Then airspeed = 1 MoveEntity plane,0,0,airspeed ;Smooth Chase Camera PositionEntity campivot,EntityX(plane,1),EntityY(plane,1),EntityZ(plane,1) piv_pitch# = CurveValue(piv_pitch,EntityPitch(plane),80) piv_yaw# = CurveValue(piv_yaw,EntityYaw(plane),80) RotateEntity campivot,piv_pitch,piv_yaw,0 UpdateWorld RenderWorld Text 5,5,"Speed=" + airspeed*540 ;Make a Crosshair Color 255,255,255 Line MouseX()-3,MouseY(),MouseX()+3,MouseY() Line MouseX(),MouseY()-3,MouseX(),MouseY()+3 Flip Wend End ;-CurveValue-; Function curvevalue#(current#,destination#,curve) current#=current#+((destination#-current#)/curve) Return current# End Function