Another 3d asteroids question
Blitz3D Forums/Blitz3D Beginners Area/Another 3d asteroids question
| ||
Gday All I have searched the forums & found plenty of info on the subject however i haven't found anyone with the same problem i have. The problem is on some angels (around the 22.5 & 292.5 angels) when the ship is accelerating the ship tends to pull to one side, even if the ship has come to a complete stop (EDIT: & then starts to accelerate again.) & the problems is visually amplified when firing. Could someone take a look at it & offer any suggestion as to why this would be happening. Any help would be greatly appreciated. Cheers. :) No media is needed. left & right arrows to turn, up to accelerate & space to fire. |
| ||
I think the problem is that you are limiting the top speed on each axis. See the MagV code for a better solution. Is this any better?Graphics3D 800,600,32,2 SetBuffer BackBuffer() x# = 0 y# = 0 Speed# = 0.025 angel# = 0 rot# = 0 Global PX# = 0 Global PY# = 0 Global pvx# = 0 Global pvy# = 0 AmbientLight 50,50,50 light = CreateLight(2) PositionEntity light,0,50,0 LightRange light,200 camera = CreateCamera() PositionEntity camera,0,100,0 RotateEntity camera,90,0,0 CameraProjMode camera,2 CameraZoom camera,.02 CameraRange camera,1,1500 Global cube = CreateCube() EntityColor cube,255,0,0 PositionEntity cube,x#,0,0 EntityFX cube,1 Global mesh = CreateCone() ScaleEntity mesh,2,1,3 RotateMesh mesh,90,0,0 PX# = 10 PY# = 10 PositionEntity mesh,PX#,0,PY# piv = CreatePivot(mesh) PositionEntity piv,0,0,-1 sphere = CreateSphere(20) PositionEntity sphere,-20,-1200,20 ScaleEntity sphere,10,10,10 RotateEntity sphere,75,0,-10 light2=CreateLight(2) PositionEntity light2,-100,-1150,50 LightColor light2,0,0,255 LightRange light2,500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;main loop;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; While Not KeyDown (1) ;angel# = EntityYaw(mesh)+90 TurnEntity mesh, 0, rot#, 0 ;RotateEntity mesh,0,rot#,0 rot# = ( KeyDown(203) - KeyDown(205 ) ) * 4.0 ; If KeyDown(203) Then ; rot# = 4;rot + 4 ; Else If KeyDown(205) Then ; rot# = -4;rot - 4 ; End If If KeyDown(200) Then create_flame(piv,Rnd(-.5,.5),0,0,Rnd(10,20)) TFormVector 0,0, speed, mesh, 0 pvx# = pvx# + TFormedX() ;Cos(angel#)*speed pvy# = pvy# + TFormedZ() ;Sin(angel#)*speed End If MagV# = Sqr( pvx * pvx + pvy * pvy ) If MagV > .5 Then pvx = pvx * ( .5 / MagV ) pvy = pvy * ( .5 / MagV ) EndIf ; If pvx > .5 Then ; pvx = .5 ; Else If pvx < -.5 ; pvx = -.5 ; End If ; ; If pvy > .5 Then ; pvy = .5 ; Else If pvy < -.5 Then ; pvy = -.5 ; End If PX# = PX# + pvx# PY# = PY# + pvy# pvx = pvx *.99 pvy = pvy *.99 ;;;;;keep player in bounds;;;;;; PositionEntity mesh,PX#,0,PY# If PX# < -51 Then PX# = 50 Else If PX# > 51 Then PX# = -50 Else If PY# < -41 Then PY# = 40 Else If PY# > 41 Then PY# = -40 End If ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; If KeyDown(57) Then create_bullet() End If ;;;;;;;;;fire cube;;;;;;;;;;;;;; X# = X# - .2 Y# = Y# - .2 PositionEntity cube,x#,0,y# If x# < -51 Then x# = 50 Else If x# > 51 Then x# = - 50 Else If y# < -41 Then y# = 40 Else If y# > 41 Then y# = -40 End If TurnEntity cube,Rnd(1,2),Rnd(1,2),Rnd(1,2) create_flame(cube,Rnd(-1,1),0,Rnd(-1,1),Rnd(50,100)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; TurnEntity sphere,0,.1,0 update_flame() update_bullet() Delay 1 UpdateWorld RenderWorld Flip Wend ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;end loop;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; End ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;types & functions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Type flame Field life% Field scale# Field x#,y#,z# Field obj Field scalered# Field alpha# Field R#,G#,B# End Type Function create_flame(entity,x#,y#,z#,life#) f.flame = New flame f\obj = CreateSphere(10,entity) f\R# = 255 f\G# = 255 f\B# = 0 EntityColor f\obj,f\R,f\G,f\B EntityFX f\obj,1 EntityBlend f\obj,3 f\scale# = Rand(1,1.2) f\alpha# = 1 f\life = life# f\scalered = f\scale / f\life PositionEntity f\obj,x,y,z EntityParent f\obj,0 End Function Function update_flame() For f.flame = Each flame f\G = f\G - Rand(0,10) EntityColor f\obj,f\R,f\G,f\B f\scale = f\scale - f\scalered f\alpha = f\alpha - f\scalered ScaleEntity f\obj,f\scale,f\scale,f\scale EntityAlpha f\obj,f\alpha f\life = f\life - 1 If f\life < 0 Then FreeEntity f\obj Delete f End If Next End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Type bullet Field obj Field life# End Type Function create_bullet() b.bullet = New bullet b\obj = CreateSphere(10,mesh) ScaleEntity b\obj,.25,.25,.25 PositionEntity b\obj,0,0,1 EntityFX b\obj,1 b\life = 50 EntityParent b\obj,0 End Function Function update_bullet() For b.bullet = Each bullet MoveEntity b\obj,0,0,2 b\life = b\life - 1 If b\life < 0 Then FreeEntity b\obj Delete b EndIf Next End Function |
| ||
Cheers Stevie G. This is heaps better. I will have to go over the MagV part in more detail to see what it is all doing. I do like the way the ship is more responcive in turns with acceleration. Is there a way to get the slide kind of effect with the turns under acceleration with this code? (EDIT: Just figured it out, i changed the speed value to a smaller number.) Dont know which way i will go yet. Cheers. |