Align myPlayer

Blitz3D Forums/Blitz3D Programming/Align myPlayer

What is the best way to align my player mesh when it is on top of a nother mesh, llike a ramp? Right now I'm using a cube, but when the cube goes up the ramp I need it to angle up, etc?

I was thinking o using four other smaller cubes positioned at the front, back, left and right, and then using those to align my player? Or should i perform a seriies of linepicks to estimate how far the ground is from each direction, or? Any other suggestions? I'm going to go take some tylenol.

A very simple method... Make sure the meshes you want to collide with have entitypickmode set.

Linepick entityx( cube ) , entityy( cube ) - 50 , entityz( cube ) , 0, 100, 0
aligntovector cube , pickednx , pickedny, pickednz , 2


Alternatively, using biltz collisions ... check out the driver demo in the 3dsamples / mak directory.

Stevie

Stevie

Do a linepick, straight down, from the position of the mesh. Grab the normals from the PickedNX(),NY() and NZ() and stick them in the aligntovector command.

Too slow Joe!

dam... may as well have a bit of code to demonstrate properly ;o), joe. You MUST set a pickmode on entities you want to align with :o)

;linepick example by RossC

Graphics3D 800,600
SetBuffer BackBuffer()


Global camera = CreateCamera()
Global light = CreateLight()

Global player = CreateCone()
EntityType player,1
EntityRadius player,1
EntityColor player,50,70,255
PositionEntity player,0,0.5,0

Global cam_piv = CreatePivot(player)
PositionEntity cam_piv,0,2,-8

Global tex=CreateTexture(64,64,1+8)
SetBuffer TextureBuffer(tex)
For loop=0 To 3000
	Color Rnd(190,255),Rnd(190,255),Rnd(190,255)
	Rect Int(Rnd(0,63)),Int(Rnd(0,63)),1,1
Next
Color 255,255,255

SetBuffer BackBuffer()

Global plane=CreatePlane()
EntityType plane,2
EntityColor plane,200,100,120
EntityTexture plane,tex
EntityPickMode plane,2


Global sphere=CreateSphere(10)
ScaleEntity sphere,10,3,10
EntityPickMode sphere,2
EntityType sphere,2
PositionEntity sphere,-2,0,19

Collisions 1,2,2,2; set up collisions between the ground and the player

Global jump_force#
Global jump_flag=0; set jump flag to 'no jump'
Global gravity#=0.9; set gravity value

While Not KeyHit(1)

	; this part is the linepick. The tform part, is to make sure the linepick is done from the players
	; actual rotation, straigh down.
	TFormVector 0,-10,0,player,0
	; the values from the tform then get used in the linepick command. if you just substitute your
	; variable for the player into here, everything will be cool!
	LinePick(EntityX(player,True),EntityY(player,True),EntityZ(player,True),TFormedX(),TFormedY(),TFormedZ()); do a linepick straight down form the players location
	; aligns the player to the scenery, whatever has has a pickmode set.
	AlignToVector player,PickedNX(),PickedNY(),PickedNZ(),2,0.1
	
	If KeyDown(200) Then MoveEntity player,0,0,0.1
	If KeyDown(208) Then MoveEntity player,0,0,-0.1
	If KeyDown(203) Then TurnEntity player,0,1,0
	If KeyDown(205) Then TurnEntity player,0,-1,0	
	
	update_camera()
	
	UpdateWorld
	RenderWorld
	Text 0,0," Press Space to jump. Arrow keys to move!"
	;DebugLog(" pickedy="+PickedY())
	Flip
Wend
End

Function update_camera()
	PointEntity camera,cam_piv
	MoveEntity camera,0,0,EntityDistance#(camera,cam_piv)/40.0
	PointEntity camera,player
End Function


thank you very much guys, and for the code. happy coding!