Tire brakes trace on road

Blitz3D Forums/Blitz3D Programming/Tire brakes trace on road

Hiya Naughty,

I used particles to create a tyre texture in snow - see here:


This was generated by particle candy.

But the trails ones were using this code and no textures were employed:

THIS CODE IS FROM ROCKET BOARDERS a brilliant little game but I forgot who developed it sorry - but they should have credit for developing the functions, I just used them. :)

[edit thanks to Gabriel for this info: Rocket Boards was developed by Ben Gillbanks ]

To begin in your set up you need this:

; TRAILS **********************
Const trail_update=1				; trail update frequency (lower number updates more often)
Const maxVerts=200					; maximum number of verts per trail object (polygons * 2)
Global Trailson= False
Type trail
	Field id
	Field tdx#[maxVerts], tdy#[maxVerts], tdz#[maxVerts]
	Field update
	Field surface
	Field point1, point2
	Field Trailson 
End Type
; TRAILS **********************


Then call the CREATE function and pass parameteres to it to start trails. Every update call the UPDATE TRAILS function, and should you wish to stop the trails call the free trails function. i.e. if your car leaps a cravass or flies off a ramp etc.

The update takes care of keeping a lid on the max number of polys used (200 in my game).


;-----------------
;update all trails
;-----------------
Function UpdateTrails()
	
	
	Local x#,y#,z#
	
	;loop through all trails
	For t.trail = Each trail
		
		
		If Trailson = True Then
		; Move the trail pieces along.
			t\update=t\update+1 : If t\update=trail_update Then t\update=0
			
		;update				
			If t\update=0
				For i=2 To CountVertices(t\surface)-1
					t\tdx[i] = (VertexX(t\surface,i-2) - VertexX(t\surface,i))/trail_update
					t\tdy[i] = (VertexY(t\surface,i-2) - VertexY(t\surface,i))/trail_update
					t\tdz[i] = (VertexZ(t\surface,i-2) - VertexZ(t\surface,i))/trail_update
				Next
			End If
			
			For i=2 To CountVertices(t\surface)-1
				VertexCoords(t\surface,i,VertexX(t\surface,i)+t\tdx[i],VertexY(t\surface,i)+t\tdy[i],VertexZ(t\surface,i)+t\tdz[i])
			Next
			
			EntityAlpha t\id,Abs(movespeed)/50
			
		;position the first two verts at the back of yourCharacter
			VertexCoords(t\surface,0,EntityX(t\point1,1),EntityY(t\point1,1),EntityZ(t\point1,1))
			VertexCoords(t\surface,1,EntityX(t\point2,1),EntityY(t\point2,1),EntityZ(t\point2,1))
			
		End If
		
	Next
	
End Function

;---------------------
;create a trail object
;---------------------
Function CreateTrail(point1,point2,polys=100,alpha#=1)
	
	Local x#,y#,z#
	Trailson = True ; ensure TRAILS are turned on
	t.trail=New trail
	
	;create mesh and set properties
	mesh = CreateMesh()
	t\surface = CreateSurface(mesh)
	t\id = mesh
	
	;check there are two trail strat points
	If point1=False Then RuntimeError "You must specify 'point1' for one side of the trail" Else t\point1=point1
	If point2=False Then RuntimeError "You must specify 'point2' for one side of the trail" Else t\point2=point2
	
	;mid pount between two trial objects
	x=(EntityX(t\point1,1)+EntityX(t\point2,1))/2
	y=(EntityY(t\point1,1)+EntityY(t\point2,1))/2
	z=(EntityZ(t\point1,1)+EntityZ(t\point2,1))/2
	
	;create polygons
	For i=0 To polys
		AddVertex t\surface,x,y,z,Float(i)/Float(polys),1,0
		AddVertex t\surface,x,y,z,Float(i)/Float(polys),0,0
		If i>0
			AddTriangle t\surface,i*2,i*2-1,i*2-2
			AddTriangle t\surface,i*2,i*2+1,i*2-1
		End If
	Next
	
	;set trail properties
	EntityFX mesh,17
	EntityAlpha mesh,alpha
	
	Return mesh
	
End Function

;--------------------------------
;free trail and delete trail type
;--------------------------------
Function free_trail(id)
	
	For t.trail=Each trail
		
		If t\id=id
			t\Trailson = False ; turn trails off PMC
			FreeEntity t\id
			Delete t
		EndIf
	Next
	
	Return True
	
End Function