Car movement in 3d

Blitz3D Forums/Blitz3D Beginners Area/Car movement in 3d

Insane Games(Posted 2003) [#1]
Hi to all! I'm trying to make a car movement where the wheels make is what make the path... i wan't to do something like this: http://venisproductions.com/games/drivers_ed/drivers_ed.html
Look my code... and please help me tks!!!

Graphics3D 640,480,16,2
SetBuffer BackBuffer()

camera = CreateCamera()
PositionEntity camera,0,5,-10
RotateEntity camera,30,0,0

pivo = CreatePivot()

roda1 = CreateSphere(10,pivo)
roda2 = CreateSphere(10,pivo)
ScaleEntity roda1,.5,1,1
ScaleEntity roda2,.5,1,1
PositionEntity roda1,-2,0,0
PositionEntity roda2,2,0,0

While Not KeyHit(1)
	
If KeyDown(203) And virando# < 30
virando# = virando# + 1
EndIf
	
If KeyDown(205) And virando# > -30
virando# = virando# - 1
EndIf

If KeyDown(200) And andando# < 3
andando# = andando# + 0.03
EndIf
	
If KeyDown(208) And andando# > -2
andando# = andando# - 0.03
EndIf
	
RotateEntity roda1,0,virando#,0
RotateEntity roda2,0,virando#,0
	
TurnEntity pivo,0,virando#,0
MoveEntity pivo,0,0,andando#
	
UpdateWorld
RenderWorld
Text 10,10,"Virando: "+virando#
Text 10,20,"Andando: "+andando#
Flip

Wend



Ross C(Posted 2003) [#2]
eh.... hey. Is there nayway you can re-pharse that question. I don't understand. :)


Insane Games(Posted 2003) [#3]
Sorry eheheh, i want to make a car movement like the shockwave... that's all!

Tks


Jeppe Nielsen(Posted 2003) [#4]
Not ultra realistic, but still.. :)
Const gravity#=-0.01 ;gravity constant
Graphics3D 640,480,16,2

Const car_col=1
Const world_col=2
Collisions car_col,world_col,2,2

light=CreateLight(1)
RotateEntity light,30,20,0

tex=CreateTexture(64,64,1+8)
SetBuffer TextureBuffer(tex)
Color 255,0,0
Rect 0,0,64,64,1
Color 255,255,255
Rect 0,0,32,32,1
Rect 32,32,32,32,1
SetBuffer BackBuffer()

plane=CreatePlane()
EntityTexture plane,tex
ScaleTexture tex,10,10
EntityAlpha plane,0.5
CreateMirror()

EntityType plane,world_col


For n=1 To 10

If Rnd(10)<5

sphere=CreateSphere(16)

Else

sphere=CreateCube()

EndIf

EntityType sphere,world_col
PositionEntity sphere,Rnd(-40,40),Rnd(2),Rnd(-40,40)
EntityColor sphere,Rnd(255),Rnd(255),Rnd(255)

Next


camera=CreateCamera()
CameraClsColor camera,0,0,255


car.car=carnew(0,5,0)

Repeat
TFormPoint 0,5,-8,car\e,0

dx#=(TFormedX()-EntityX(camera))*.01
dy#=(TFormedY()-EntityY(camera))*.01
dz#=(TFormedZ()-EntityZ(camera))*.01

TranslateEntity camera,dx,dy,dz

PointEntity camera,car\e

carcontrol()
carupdate()

RenderWorld()

Flip


Until KeyDown(1)
End


Type car

Field e ;entity

Field x#,y#,z# ; position in 3d-space

Field vx#,vy#,vz# ; velocity

Field ax#,ay#,az# ; acceleration

Field wheel[3]

Field wheelangle#

End Type


Function carnew.car(x#,y#,z#)
	
	c.car=New car
	
	c\x#=x#
	c\y#=y#
	c\z#=z#
	
	c\e=CreateCube()
	ScaleMesh c\e,2,0.5,3
	
	For n=0 To 3
		c\wheel[n]=CreateSphere(8,c\e)
		ScaleMesh c\wheel[n],0.2,1,1
	Next
	PositionEntity c\wheel[0],-2.2,-0.5,2.8
	PositionEntity c\wheel[1],2.2,-0.5,2.8
	PositionEntity c\wheel[2],-2.2,-0.5,-2.8
	PositionEntity c\wheel[3],2.2,-0.5,-2.8
	
	
	EntityType c\e,car_col
	EntityRadius c\e,1.5
	
	PositionEntity c\e,c\x,c\y,c\z
	
	Return c
	
End Function

Function carupdate()
	
	For c.car=Each car
	
		c\vy#=c\vy#+gravity#
		
		c\vx#=c\vx#+c\ax#
		c\vy#=c\vy#+c\ay#
		c\vz#=c\vz#+c\az#
		
		c\x#=EntityX(c\e)
		c\y#=EntityY(c\e)
		c\z#=EntityZ(c\e)
		
		TranslateEntity c\e,c\vx,c\vy,c\vz
	
	Next
	
	UpdateWorld()
	
	For c.car=Each car
		
		;correct velocity if collided
		c\vx=(EntityX(c\e)-c\x)
		c\vy=(EntityY(c\e)-c\y)
		c\vz=(EntityZ(c\e)-c\z)
		
		
		;slow down due to friction
		If EntityCollided(c\e,world_col)
			
			c\vx#=c\vx*0.98
			c\vy#=c\vy*0.98
			c\vz#=c\vz*0.98
		
		EndIf
		
		c\ax#=0
		c\ay#=0
		c\az#=0
		
	Next
	
End Function


Function carcontrol()
	
	For c.car=Each car
		
		If KeyDown(200)
					
			TFormVector 0,0,0.02,c\wheel[0],0
			
			c\ax#=TFormedX()
			c\ay#=TFormedY()
			c\az#=TFormedZ()
			
			TurnEntity c\e,0,c\wheelangle#/10,0
			
		EndIf
		
		If KeyDown(208)
			
			c\vx=c\vx*0.99
			c\vy=c\vy*0.99
			c\vz=c\vz*0.99
			
		EndIf
		
		If KeyDown(57)
			
			TFormVector 0,0.05,0,c\e,0
			
			c\ax#=c\ax+TFormedX()
			c\ay#=c\ay+TFormedY()
			c\az#=c\az+TFormedZ()
			
									
		EndIf
		
		If KeyDown(203)
			
			c\wheelangle#=c\wheelangle#+2
			If c\wheelangle#>50
				c\wheelangle#=50
			EndIf
			
			RotateEntity c\wheel[0],0,c\wheelangle#,0
			RotateEntity c\wheel[1],0,c\wheelangle#,0
					
		EndIf
		
		If KeyDown(205)
			
			c\wheelangle#=c\wheelangle#-2
			If c\wheelangle#<-50
				c\wheelangle#=-50
			EndIf
			
			RotateEntity c\wheel[0],0,c\wheelangle#,0
			RotateEntity c\wheel[1],0,c\wheelangle#,0

			
		EndIf
		
		
	Next
	
	
	
End Function



Insane Games(Posted 2003) [#5]
Tks Jeppe! I like!! Nice!


eBusiness(Posted 2003) [#6]
Graphics 800,600
speed#=0
posx#=400
posy#=320
rot#=0
wheel#=0
While KeyDown(1)=0
	Delay 40
	If KeyDown(200) Then speed=speed+.4
	If KeyDown(208) Then speed=speed-.2
	speed=speed*.95
	speed2#=Abs(speed)
	If speed2<.01 Then speed2=.01
	If KeyDown(203) Then
		wheel=wheel+.2
	Else If KeyDown(205) Then
		wheel=wheel-.2
	Else If wheel<.2 And wheel>-.2 Then
		wheel=0
	Else If wheel>0 Then
		wheel=wheel-.2
	Else If wheel<0 Then
		wheel=wheel+.2
	End If
	If wheel>1.8 Then wheel=1.8
	If wheel<-1.8 Then wheel=-1.8
	If wheel>3/speed2 Then wheel=3/speed2
	If wheel<-3/speed2 Then wheel=-3/speed2
	rot=rot+wheel*speed
	posx=posx+Sin(rot)*speed
	posy=posy+Cos(rot)*speed
	Cls
	WritePixel posx,posy,16777215
	WritePixel posx+Sin(rot)*20,posy+Cos(rot)*20,16777215
	Text 0,0,speed
Wend


This should be a pretty realistic car. Funny game you found there.