Alignment problems.

Blitz3D Forums/Blitz3D Beginners Area/Alignment problems.

I am trying to do a driving game where you race in a walled in track. The track has both hills and long banked corners. The track and walls are seperate 3ds models which are loaded in.

I have got the player's vehicle to follow the hills properly. But when I go round the banked curve the player comes out of it slightly misaligned (as in not looking straight ahead). The vehicle is driveable as normal but just isn't facing the correct direction.

Anyone know what might cause this?

Also I have the the collision for the walls set to 2,1 (polygon,stop) but when the player hits a wall they will either drive straight through it or move over it. Again, any ideas why?

The code as it stands is below if it helps. A couple of notes though:

1) I started with Gravity on, but had to disable it as I could not get the correct alignment when using the linepick command with it on for some reason.

2) The objects are a little large (for ease when modeling them as I can adjust them more accurately) hence the large scale factor.


Any suggestions are really welcomed as this is already proving to be a lot harder than I imagined :(

Max

Graphics3D 800,600,16,2
Text 320,200,"Please Wait, Loading Data...."

SetBuffer BackBuffer()


; Setup contants and varibles as used in the driver example and modified for what I think I need.

Const GRAVITY#=-5
Const BODY=1,WALL=2,RACETRACK=3,SHIPPIVOT=4

Global dist_above_track# = 10			;	Distance Above Track That Ship Hovers.
Global dist_away_from_wall# = 50
Global bank_angle# = 0
Global max_speed# = -500				;	Maximum Speed The Ship Can Go.
Global speed# = 0						;	Set Speed To 0 At Start.
Global displayspeed# = 0

; Load required Track & Walls and set them up as needed. This includes linking to any variables.

Global track=LoadMesh ("Media/TestTrack3a.3ds")
Global walls=LoadMesh ("Media/TestTrack3b.3ds")
Global scenery=LoadMesh ("Media/TestTrack3c.3ds")


PositionEntity track,0,0,0
PositionEntity walls,0,0,0
PositionEntity scenery,0,0,0
RotateEntity track,0,0,-90
RotateEntity walls,0,0,-90

EntityType track,RACETRACK
EntityType walls,WALL

EntityPickMode track,2
EntityPickMode walls,2

tex=LoadTexture( "Media/tiles.jpg" )
ScaleTexture tex,50,50
EntityTexture track,tex



; Now do the same for the ship (this replaces the car in the driver example).

Global ship=LoadMesh ("Media/fighter.3ds")
PositionEntity ship,0,20,0
EntityShininess ship,1
EntityType ship,BODY

ScaleEntity track,.05,.05,.05
ScaleEntity walls,.05,.05,.05
ScaleEntity scenery,.05,.05,.05
ScaleEntity ship,.05,.05,.05


; Set up the main light for the scene.

light=CreateLight()
PositionEntity (light,0,10,-10)


; Now get the camera up and running...

camera=CreateCamera()
CameraRange camera,1,10000
CameraFogMode camera,1
CameraFogRange camera,100,9000
PositionEntity camera,0,25,70
PointEntity camera,ship


; Setup collisions

Collisions BODY,RACETRACK,2,2
Collisions BODY,WALL,2,1


; Setup other variables

camx#=0				; Camera X Angle.
camy#=0				; Camera Y Angle.
camz#=0				; Camera Z Angle.
pitch#=0			; Camera & Ship Rotation Angle.


; Okay that should be everything up and running. Now it is time to do the main program loop.

While Not KeyHit(1)

	
;move ship
	
If KeyDown(203) 

	camy=camy+3
	TurnEntity ship,0,3,0	

ElseIf KeyDown(205) 

	camy=camy-3
	TurnEntity ship,0,-3,0

EndIf

If KeyDown(200) 
If speed>max_speed

	speed=speed-20
	If speed<max_speed
		speed=max_speed
	EndIf
	
EndIf
	
Else If KeyDown(208)

	speed=speed+20
	If speed>0 
		speed=0
	EndIf

Else
		speed=speed+5
		If speed>0
			speed=0
		EndIf
	
EndIf

sx#=EntityX(ship,True)
sy#=EntityY(ship,True)
sz#=EntityZ(Ship,True)

LinePick sx,sy,sz,0,-20,0

If PickedEntity()<>0
		PositionEntity ship,sx,PickedY()+dist_above_track,sz
		AlignToVector ship,PickedNX(),PickedNY(),PickedNZ(),2,0.5
EndIf

	realspeed=speed/10
	displayspeed=speed
	MoveEntity ship,0,0,realspeed
;	TranslateEntity ship,0,GRAVITY,0

	; Reset camera position and view.
	PositionEntity camera,EntityX(ship),EntityY(ship),EntityZ(ship)
	RotateEntity camera,0,camy,pitch
	MoveEntity camera,0,20,70
	AlignToVector camera,PickedNX(),PickedNY(),PickedNZ(),2,0.5
	PointEntity camera,ship
	
	

	
	UpdateWorld
	RenderWorld
	
	Text 320,500,"Racer V0.01"
	Text 320,520,"Speed:"
	Text 380,520,displayspeed
	Flip

Wend
End


Without having your models to test this out I wonder if this:

AlignToVector ship,PickedNX(),PickedNY(),PickedNZ(),2,0.5

might have something to do with it. The command reference lists this as:

AlignToVector entity,vector_x#,vector_y#,vector_z#,axis[,TRANSLATIONrate#] (I added the word TRANSLATION)

OK... so you have everything set and TRANSLATIONrate is set at .5 ( 0 being smooooth and 1 being SNAP)

I have to ask if the car ever straightens out??? and why is the AXIS set at 2? The Y axis.(I admit I am unsure which is used to describe LEFT RIGHT steering but maybe either another call for the alignment of the L/R mode???)

I am shooting through my hat here...

RZ

Its the camera that is mis-aligned ;). check out your other post in the blitz3d programming or check your email max :o)