Pointentity Problem

Blitz3D Forums/Blitz3D Programming/Pointentity Problem

If you add a bit of momentum to the missile it seems to hit the target eventually ...

Graphics3D 640,480,16,1

Global CAMERA = CreateCamera()
PositionEntity CAMERA, 0,0,-100 ;50,0
;RotateEntity CAMERA, 90,0,0

Global TARGET = CreateCube()
ScaleEntity TARGET, 2,2,2
EntityColor TARGET, 255,0,0

Type MissileT
	Field Mesh
	Field Flame
	Field Vx#, Vy#
	Field Acceleration#
	Field Momentum#
	Field Turnrate#
End Type
Global MISSILE.missileT = MISSILEcreate( .01, .99, .2 )

;init target
PositionEntity TARGET, Rand(-50,50 ), Rand( -50,50 ) ,0

While Not KeyDown(1)

	;target reached or spawn new target position
	If KeyDown( 57 ) Or EntityDistance( MISSILE\mesh, TARGET ) < 6
		PositionEntity TARGET, Rand(-50,50 ), Rand( -50,50 ) , 0
	EndIf
	
	MISSILEupdate()
	RenderWorld()
	Flip
	
Wend

End

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

Function MISSILEcreate.MissileT( Acceleration# , Momentum#, TurnRate# )

	;max speed = Acceleration / ( 1- Momentum )

	m.missileT = New missileT
	m\Acceleration = Acceleration
	m\Momentum = Momentum
	m\TurnRate = TurnRate
	m\Mesh = CreateCone()
	FitMesh m\Mesh, -1,0,-1,2,6,2
	m\Flame = CreateCone( 8 , False, m\Mesh )
	RotateMesh m\Flame, 0,0,-180
	FitMesh m\Flame,-1,-4,-1,2,4,2
	EntityColor m\Flame, 255,128,0
	
	Return m

End Function

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

Function MISSILEupdate()

	For m.missileT = Each missileT
		
		;turn
		POINT( m\Mesh, TARGET, m\TurnRate )
		
		;move
		TFormVector 0,m\Acceleration, 0,m\Mesh, 0
		m\Vx = m\Vx * m\Momentum + TFormedX()
		m\Vy = m\Vy * m\Momentum + TFormedY()
		TranslateEntity m\Mesh, m\Vx, m\Vy, 0		

		;animate flame
		ScaleEntity m\Flame, 1,Rnd( .5, 5 ), 1
		
	Next

End Function

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

Function POINT( Source , Target, Rate#=1.0 )

	TFormPoint 0,0,0 , Target, Source
	DeltaRoll# = VectorYaw( TFormedX(), 0 , TFormedY() )
	
	If Abs( DeltaRoll ) > Rate 
		TurnEntity Source, 0,0,DeltaRoll * Rate
	Else
		TurnEntity Source, 0,0,DeltaRoll
	EndIf

End Function