Ok, i managed to knock together this:
It also works if the camera rolls, as you are translating the targets co-ords to the ships local co-ords. It seems to be pretty robust.
It also works if the camera rolls, as you are translating the targets co-ords to the ships local co-ords. It seems to be pretty robust.
Graphics3D 800,600 SetBuffer BackBuffer() Global camera = CreateCamera() Global light = CreateLight() Global ship = CreateSphere() EntityParent camera,ship PositionEntity camera,0,0,-10 Dim cubes(20) For loop = 0 To 20 cubes(loop) = CreateSphere(2) EntityColor cubes(loop),Rnd(50,255),Rnd(50,255),Rnd(50,255) PositionEntity cubes(loop),Rnd(-30,30),Rnd(-30,30),Rnd(-30,30) Next ; set up the target and arrow pointer Global target = CreateCube() EntityColor target,200,40,40 PositionEntity target,10,3,20 Global arrow = CreateCone() Global pivot = CreatePivot() EntityParent arrow,pivot PositionEntity arrow,0,4,0 ScaleEntity arrow,0.25,0.25,0.25 EntityColor arrow,40,40,200 EntityParent pivot,ship While Not KeyHit(1) EntityColor target,Rnd(30,230),Rnd(30,230),Rnd(30,230) If KeyDown(203) Then RotateEntity ship,EntityPitch(ship,True),EntityYaw(ship,True)+1,EntityRoll(ship,True),True If KeyDown(205) Then RotateEntity ship,EntityPitch(ship,True),EntityYaw(ship,True)-1,EntityRoll(ship,True),True If KeyDown(200) Then RotateEntity ship,EntityPitch(ship,True)+1,EntityYaw(ship,True),EntityRoll(ship,True),True If KeyDown(208) Then RotateEntity ship,EntityPitch(ship,True)-1,EntityYaw(ship,True),EntityRoll(ship,True),True If MouseDown(1) Then MoveEntity ship,0,0,0.1 If MouseDown(2) Then MoveEntity ship,0,0,-0.1 ; transform the targets X,Y,Z co-ords to the ships local co-ords TFormPoint EntityX(target,True),EntityY(target,True),EntityZ(target,True), 0, ship ; work out the angle between the ship's local co-ords (0,0,0) and the targets tranformed co-ords angle = ATan2( TFormedY(), TFormedX()) angle = angle - 90 ; adjust for blitz rotation system RotateEntity pivot,0,0,angle ; rotate the arrow pivot to point at the target. UpdateWorld RenderWorld Text 0,0," Arrow Keys to turn. Mouse button left to move forward and mouse button right to move backwards" Flip Wend