Help with elite programming problem

Blitz3D Forums/Blitz3D Programming/Help with elite programming problem

I have created a basic elite combat system but for some reason the ship doesnt point towards the target, it pitches and rolls so its in view but then goes wild. Anyone have any ideas on how to fix this one? Ive been working on it a while but I can get it close but it still doesnt work 100% strangely the angles I have dont point directly towards the target.

you can download the source and model here

Thanks for your help

Personally, I'd let Blitz handle that rather than trying to calculate it. I'd take the easy route as I'm no good at maths and stuff like that.

I haven't looked at your code, but you should be able to simply use AlignToVector along the lines of this:
dirx# = targetx - EntityX(ship,True)
diry# = targety - EntityY(ship,True)
dirz# = targetz - EntityZ(ship,True)

AlignToVector ship,dirx,diry,dirz,3,0.01

; And if you want to keep the ship up straight add this:
; AlignToVector ship,0,1,0,2,0.01
The 0.01 part determines the speed of the change/alignement.

As I said, I haven't looked at your code, but this should work flawlessly.

fredborg: Thanks will have a look :)

Puki: Blitz doesnt seem to rotate it right this is why I wanted to do the math route :)

I'm not any help on the rotation. I just wanted to say I'm happy to see your still working on this one!

Dont forget the roll parameter for using PointEntity. I had similar issues with some of the game-engine stuff in Galactic Allegiance.

UNfortunately, my main PC's out of action at the mo, (which means so's Blitz and my sourcecode) if this isnt sorted by about 7 days time, Il get back to you.

For full 360 degree rotation on any axis you could try to use Quaternions ( or matrices). Euler angles are not very good for this purpose due to gimbal lock - which may be what you are experiencing.
You should try and only use Eulers at the first and last stage of converting to/from a quat or matrix.

Use Aligntovector as fredborg says. This command uses quats internally so I'd suggest using these to align on roll and pitch axis and avoid the dreaded Gimbal Lock.

When flying in Elite the general idea was to roll until the ship was directly above you then pitch to match.

Stevie

fredborg: The function you provides is brilliant for missiles but Elite ships only use pitch and roll to point towards thier target, they roll till the target is on the y axis then pitch up/down till they are in the firing line.

I.e. the ship rolls left or right till and pitches up and down till the target is directly in front of the ship. I can get the basics but it always seems to be a little off.

Loved the original Elite, east to drop in for a few minutes, 'modern' versions require too much time investment.

Played Elite and Dungeon Master all that time ago, still great:)

Great job on this been watching for a while now, hoping to give it a go when its finished:)

Played Elite when it was released on the BBC :), got hooked from there.

Good luck, Commander Jameson.

Anyone have any way of doing this, im still looking at me code trying to make it as smooth as possible.

I've just downloaded this so I'll have a play around. Assume you don't mind if I change a few things? I can't help thinking there is a much easier way than you're currently using ;)

I'll post back with results later.

Stevie

Ok, I came up with this stripped down version of your code. Press and hold T to target the space station, hit SPACE to randomly place and rotate the Ship. Cursors to roll + pitch.

It's not perfect but should do the job and hopefully makes sense to you.

Graphics3D 640, 480, 16, 1
AmbientLight 255, 255, 255
WireFrame True

;ship
Global Cobra = CreatePivot();LoadMesh( "Models\CobraMk3.x")
Global PitchSpeed# = 1.0
Global RollSpeed# = 1.0
Global Pitch#, Roll#

;camera
Global Camera = CreateCamera( Cobra ) 
;PositionEntity Camera, 0,0,-50 
PositionEntity Camera, 0, 0, 5

;scene
Global Planet = CreateSphere() : ScaleMesh Planet, 10, 10, 10 : EntityColor Planet, 255,0,0
Global Station = CreateSphere( 3 ) : ScaleMesh Station, 2, 2, 2 : PositionEntity Station, 20, 0, 0 : EntityColor Station, 0,0,255
Global Star = CreateCube() : ScaleMesh Star, .25, .25, .25 : HideEntity Star
For l = 1 To 100
	tmp = CopyEntity( Star , Planet )
	RotateEntity tmp, Rand(-90,90 ), 0 , Rand(-180,180 )
	PositionEntity tmp, Rand(-200,200 ), Rand(-200,200 ), Rand(-200,200 )
Next

;timing
Global FPSWanted = 60
Global Timer = CreateTimer( FPSWanted )

Reset()

While Not KeyDown(1)

	WaitTimer( Timer )
	
	;reset if 'SPACE' pressed
	If KeyDown(57) Reset()

	;target if 'T' pressed
	If KeyDown( 20 )
		TARGET( Cobra , Station )
	Else
		Roll# = KeyDown( 203) - KeyDown(205)
		Pitch# = KeyDown( 200 ) - KeyDown(208)
	EndIf
	
	TurnEntity Cobra , Pitch , 0, Roll 
	MoveEntity Cobra, 0, 0, .25

	UpdateWorld()
	RenderWorld()
	scanner( 320, 420 )
	
	Color 255,0,255
	Line 300,240,340,240
	Line 320,220,320,260
	
	Flip
	
Wend
End

;===================================================
;===================================================
;===================================================

Function TARGET( Source , Target )

	TFormPoint 0,0,0 , Target, Source

	RollAngle# = VectorYaw ( TFormedX() , 0 , TFormedY() )
	Roll# = Limit( RollAngle , -RollSpeed , RollSpeed )
	If Abs( RollAngle ) < 10
		Pitch# = Limit( VectorPitch( 0 , TFormedY(), TFormedZ() ) , -PitchSpeed , PitchSpeed )
	Else
		Pitch# = 0
	EndIf

End Function

;===================================================
;===================================================
;===================================================

Function Limit#( q#, lo#, hi# )

	If q < lo q = lo
	If q > hi q = hi
	Return q
	
End Function

;===================================================
;===================================================
;===================================================

Function Reset()

	PositionEntity Cobra, Rnd( -100,100 ) , Rnd(-100,100 ), Rnd(-100,100 )
	RotateEntity Cobra , Rnd(-90,90), 0, Rand(-180,180 )
	Delay 250

End Function

;===================================================
;===================================================
;===================================================

Function Scanner(scanx,scany)

	; Scanner by Timo Souranta
	;
	;Stations And planets are white because they are greater than 500t
	;Scanner size is: Scanx X -115 to Scanx +115 (with a scale of .7)
	;Scany Y -37 to Scany +37   

	Color 255,0,0
	Oval scanx-115,scany-37 , 230,74,0
	scale# = 0.7
	Plot scanx, scany
	
	TFormPoint 0,0,0, Station, Cobra
	x# = TFormedX() *  scale
	y# = TFormedY() * -scale
	z# = TFormedZ() *  scale
	x1# = x
	y1# = - z/4 + y/2
	y2# = - z/4
	If x1 > -200 And x1 < 200 And y1 > -200 And y1 < 200 Then
		Color      255, 255, 255
		If scanx+x1>scanx-115 And scanx+x1<scanx+115 And scany+y1>scany-37 And scany+y1<scany+37
		 	scn=(scany+y1)-(scany+y2)
		 	If scn>-30 And scn<30
  		  		WritePixel scanx+x1+1, scany+y1, 256*256*255 + 256*255
  		 		Line scanx+x1, scany+y1, scanx+x1,scany+y2
			EndIf
		EndIf
	EndIf
	
End Function


Stevie

nice StevieG, i just had an elite flashback with your code!

Thanks will have a look :)

Thanks Stevie G thats exactly what im looking for :)