hovering a ship

Blitz3D Forums/Blitz3D Beginners Area/hovering a ship

Here's another example with using the normals of the line pick to align the ship to the angle of the slope. A bit jitter because of the sharp angle change between each cylinder, but illustrates the point :o)

Graphics3D 800,600
SetBuffer BackBuffer()


Global cam = CreateCamera()

Global light = CreateLight()

Global ship = CreateCube()

Dim track(9); create a dummy track out of spheres
For loop = 0 To 9
	track(loop) = CreateCylinder(40)
	ScaleEntity track(loop),3,10,2
	RotateEntity track(loop),90,0,0
	PositionEntity track(loop),-20+loop*5,0,0
	EntityPickMode track(loop),2
Next

PositionEntity cam,0,4,-20
PositionEntity ship,0,5,0

Global dist_above_track# = 3


While Not KeyHit(1)


	If KeyDown(203) Then MoveEntity ship,-0.1,0,0
	If KeyDown(205) Then MoveEntity ship,0.1,0,0


	x# = EntityX(ship,True)
	y# = EntityY(ship,True)
	z# = EntityZ(ship,True)
	
	LinePick x,y,z,0,-10,0 ; perform the line pick
	
	If PickedEntity() <> 0 Then ; make sure an entity has been picked
		PositionEntity ship,x,PickedY()+ dist_above_track,z ; place the ship above the pickedy() co-ord
		AlignToVector ship,PickedNX(),PickedNY(),PickedNZ(),2,0.5
	End If



	UpdateWorld
	RenderWorld
	Text 0,0,(PickedY()+ dist_above_track)
	Flip
Wend
End