How do you turn an object towards another

Blitz3D Forums/Blitz3D Programming/How do you turn an object towards another

D_Town_Tony(Posted 2004) [#1]
Anyone have an easy way to get one object to slowly turn towards another object as opposed to to instantly turning around?


N(Posted 2004) [#2]
Function GradTurn(E1,E2,Speed#)
	If E1 = 0 Or E2 = 0 Then Return False
	TX# = DeltaPitch(E1,E2)
	TY# = DeltaYaw(E1,E2)
	RotateEntity E2,EntityPitch(E2)+TX,EntityYaw(E2)+TY,EntityRoll(E2)  ;; done like this so it doesn't do a slightly odd turning.. (e.g., like if you use MouseX/YSpeed with TurnEntity)
	Return True
End Function


Something like that.


Bot Builder(Posted 2004) [#3]
maybe...
Function GradTurn(E1,E2,Speed#)
	If E1 = 0 Or E2 = 0 Then Return False
	TX# = DeltaPitch(E1,E2)*speed#
	TY# = DeltaYaw(E1,E2)*speed#
	RotateEntity E2,EntityPitch(E2)+TX,EntityYaw(E2)+TY,EntityRoll(E2)  ;; done like this so it doesn't do a slightly odd turning.. (e.g., like if you use MouseX/YSpeed with TurnEntity)
	Return True
End Function



N(Posted 2004) [#4]
Yeah.. woops... forgot that bit -_-


Filax(Posted 2004) [#5]
Have an idea for block some angle like : ?

Function GradTurn(E1,E2,Speed#,Min#,Max#)
If E1 = 0 Or E2 = 0 Then Return False
TX# = DeltaPitch(E1,E2)*speed#
TY# = DeltaYaw(E1,E2)*speed#
RotateEntity E2,EntityPitch(E2)+TX,EntityYaw(E2)+TY,EntityRoll(E2) ;; done like this so it doesn't do a slightly odd turning.. (e.g., like if you use MouseX/YSpeed with TurnEntity)
Return True
End Function

Because i don't find how to block an angle by example

-20=Min and Max#=90 my object become crazy :)


semar(Posted 2004) [#6]
In the code archive I've posted a 'smart turn' function, it may also be helpful.

What it does, it gently turns an entity toward another one, using the shortest path - that is, it turns the entity to left or right so that the angle to be covered is the smallest.

You find it here:
http://www.blitzbasic.com/codearcs/codearcs.php?code=360

Sergio.


D_Town_Tony(Posted 2004) [#7]
Thanks for all the help guys.


D_Town_Tony(Posted 2004) [#8]
I just tried the functions out and they don't want to work, pigeon's just makes them spin for some reason,
and semar's doesn't don't anything for some reason. I'm using these functions on a type so it affects 20 things a once, I don't know if this affects it.


D_Town_Tony(Posted 2004) [#9]
nevermind, I got it working.


Matty(Posted 2004) [#10]
There is an easy way to make an object face another object using aligntovector.

use:
AlignToVector Entity,VectorX,VectorY,VectorZ,Axis,Rate

set VectorX,VectorY and VectorZ as follows:
VectorX=EntityX(TargetEntity)-EntityX(CurrentEntity)
and do the same for VectorY,Z using EntityY and EntityZ

Assuming that your mesh was made with the Z-axis being "forwards" then you would set parameter "axis" to 3.

Set the rate to some value less than 1 and greater than 0 and then call this function each frame until the object is facing the target object.