aligntovector does almost behave like i want to

Blitz3D Forums/Blitz3D Beginners Area/aligntovector does almost behave like i want to

koekjesbaby(Posted 2003) [#1]
but not completely.

basically i want to let a unit rotate around its y axis untis it faces some given point. in 99% of the cases this goes perfectly well. but when the vector to align to is exaclty the opposite of the current alignment, the entity turns upside down.

should i just write my own alignfunction or is there an easier way to solve my problem?


Ross C(Posted 2003) [#2]
you could have a pivot slightly ahead of the entity you want to turn. then point the pivot at point you want to go to. move the pivot towards the point and point the entity you want to turn at the pivot. when the pivot reaches the point, reset it back infront of the entity/


Ross C(Posted 2003) [#3]
here some code to help

left and right arrow keys to turn the player
up and down key to move forwards and backwards

spacebar to turn the entity towards the target

Graphics3D 800,600
SetBuffer BackBuffer()

camera=CreateCamera()

light=CreateLight()

target=CreateCone()
PositionEntity target,0,0,20
EntityColor target,30,60,200

player=CreateCube()
EntityParent camera,player
MoveEntity camera,0,2,-5

pivot=CreatePivot()

EntityParent pivot,player
MoveEntity pivot,0,0,5

rotspeed=25 ; the higher the number the slower the rotation


While Not KeyHit(1)
	Cls
	If KeyDown(203) Then TurnEntity player,0,1,0
	If KeyDown(205) Then TurnEntity player,0,-1,0
	If KeyDown(200) Then MoveEntity player,0,0,0.2
	If KeyDown(208) Then MoveEntity player,0,0,-0.2
	
	
	If KeyHit(57) Then
					Gosub resetpivot
					EntityParent pivot,0
					pm=1
	End If
		
	If pm=1 Then Gosub updatepivot

	
	UpdateWorld
	RenderWorld

	Flip
Wend
End


.resetpivot
	RotateEntity pivot,0,EntityYaw(player),0
	PositionEntity pivot,EntityX(player),EntityY(player),EntityZ(player)+5
Return

.updatepivot
	PointEntity pivot,target
	PointEntity player,pivot
	MoveEntity pivot,0,0,EntityDistance(pivot,target)/rotspeed
	If EntityDistance#(pivot,target)<0.5 Then
				Gosub resetpivot
				EntityParent pivot,player
				pm=0
	End If
Return