Entitydistance(A,B)

Blitz3D Forums/Blitz3D Programming/Entitydistance(A,B)

Just fire out 5-6 partcicles behind the missle, each with their own velocity with slight speed variation between the half of the missle's speed and it's full speed and slight size variation.

This is by no means working code but will give you more info on the functions involved :

Call PARTICLEinit before you main loop
Call PARTICLEcreate as and when required
Call PARTICLEupdate each loop
Call PARTICLEreset when you need to clear them all

Type Particle
	Field Mesh
	Field Life#
	Field Vx#, Vy#, Vz#
End Type
Global PARTICLEnext.Particle

PARTICLEinit( 100 )

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

Function PARTICLEinit( MaxParticles )

	;create MaxParticles for recycling

	For l = 1 To MaxParticles
		p.particle = New particle
		p\Mesh = CopyEntity( PARTICLEmesh ) : HideEntity p\Mesh
		p\Life = 0
	Next

	PARTICLEnext = First p

End Function

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

Function PARTICLEcreate( Emitter , OffsetZ# , Speed# , Number = 5 )

	For No = 1 To Number

		p.particle = PARTICLEnext
	
		;reset life and show
		p\Life = 1.0
		ShowEntity p\Mesh
	
		;get world coords of emitter offset and position particle there
		TFormPoint Emitter, 0,0, OffsetZ
		PositionEntity p\Mesh, TFormedX(), TFormedY(), TFormedZ()
		
		;get velocity
		TFormVector Emitter, Rnd(-.1, .1 ) * Speed, Rnd(-.1, .1 ) * Speed, Rnd(.5, 1 ) * Speed
		p\Vx = TFormedX()
		p\Vy = TFormedY()
		p\Vz = TFormedZ()
		
		;recycle
		PARTICLEnext = After p
		If p = Null PARTICLEnext = First Particle
		
	Next

End Function

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

Function PARTICLEupdate()

	For p.particle = Each particle
	
		;only move particles that are alive
		If p\Life > 0
			p\Life = p\Life - .01 : If p\Life < 0 p\Life = 0
			If p\Life = 0
				HideEntity p\Mesh
			Else
				TranslateEntity p\Mesh, p\Vx, p\Vy, p\Vz
				EntityAlpha p\Mesh, p\Life
			EndIf
		EndIf   

	Next
	
End Function

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

Function PARTICLEreset()

	;reset all particles

	For p.particle = Each particle
	
		p\Life = 0
		HideEntity p\Mesh
		
	Next

End Function