Tire brakes trace on road

Blitz3D Forums/Blitz3D Programming/Tire brakes trace on road

Naughty Alien(Posted 2008) [#1]
..hi guys...could some give me some hints or maybe some piece of code, how to achieve tire marks on road during intense use of breaks or sliding/drifting?? I really dont have clue where to start, so i would appreciate explanation and maybe some piece of code if anyone willing to share...thank you..


Vorderman(Posted 2008) [#2]
I used a system where I had 2 pivots attached to each rear wheel (but you could use a local t-formed coord system here to remove the need for pivot entities)

I place one pivot at the point where the inside wheel edge contacts the floor, the other at the point where the outside edge contacts the floor. Done for both rear wheels this gives you 4 pivots.

I then created an empty mesh with a single surface with an appropriate material on it, such as a 50% black blend or something, as I wasn't going to texture map the skids, although that's fairly easy to do.

When a skidmark is triggered I added 4 new vertices to the surface at the position of the 4 pivots (call these L1 and L2 for the left wheel, and R1 and R2 for the right wheel) then setup a counter that decreases. Once the counter reaches zero (ie. allowing the car to skid certain distance) I add 4 more verts (L3 and L4, and R3 and R4) and create a quad polygon using L1,L2,L3 and L4, and another polygon using R1,R2,R3 and R4.

I then repeat this process for as long as the skid continues, creating 2 curved polygon skidmarks that roughly follow the path of the 2 wheels.

Varying the counter adjusts the blockiness of the skidmarks - a lower counter adds vertices more often, creating a smoother look but using more verts and polys over a certain distance - balance it to get the right look depending upon how long your skids are and how often they occur, and how close the camera is.

The only tricky bit is telling when a skid starts and ends and therefore creating a new set of start verts for each seperate skid to ensure you don't get big stretched polys across the world. You also need to keep an eye on the number of verts in the new mesh to ensure it doesn't get too high, perhaps removing the verts in order of oldest first or culling them after a certain time.


IPete2(Posted 2008) [#3]
I sometimes use particles aligned to the floor and with a short lifetime, enough to drive on and spin a little, before they disappear.

OR

As Vordeman suggests use something like the trails code (possibly in the archive) as superbly used in RocketBoards.

I can probably dig out the code if you should need it.

IPete2.


Naughty Alien(Posted 2008) [#4]
hi Ipete, I would apprechiate that function-code if you dont mind...is it possible to texture generated trails you talking about Ipete2??


Santiworld(Posted 2008) [#5]
hi, there is a sample, in blitz samples, in Mark directory -> Tron...


this is part of the code, creating a mesh with vertexs...


If add_flag
AddVertex trail_surf,EntityX(bike),2,EntityZ(bike),0,0
AddVertex trail_surf,EntityX(bike),0,EntityZ(bike),0,1
AddTriangle trail_surf,trail_vert,trail_vert+2,trail_vert+3
AddTriangle trail_surf,trail_vert,trail_vert+3,trail_vert+1
AddTriangle trail_surf,trail_vert,trail_vert+3,trail_vert+2
AddTriangle trail_surf,trail_vert,trail_vert+1,trail_vert+3
trail_vert=trail_vert+2
Else
VertexCoords trail_surf,trail_vert,EntityX(car),EntityY(car),EntityZ(car)
VertexCoords trail_surf,trail_vert+1,EntityX(car),EntityY(car),EntityZ(car)
EndIf


IPete2(Posted 2008) [#6]
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



Naughty Alien(Posted 2008) [#7]
thank you a lot Ipete2... cheers man ;)


IPete2(Posted 2008) [#8]
my pleasure Naughty!

I have to say that I used this code to great extent to produce some wonderful snow and ice trails in a 'little' game I did last year, there was a level based in the winter, and this code really added to the feel of speed and snow/ice. I am not allowed to post images of that particular project here, but I may put some on my website for you guys to oggle at.

IPete2.


Gabriel(Posted 2008) [#9]
Rocket Boards was developed by Ben Gillbanks. Still one of my favourite Blitz games of all time.


IPete2(Posted 2008) [#10]
Thanks Gabriel,

I have edited the above post to give proper credit as it should be.

IPete2.