Align to vector

Blitz3D Forums/Blitz3D Programming/Align to vector

Craig H. Nisbet(Posted 2006) [#1]
I'm making a game that has robota battling each other. They have seperate body parts. The robots are entirely AI controlled. the guns are on the torso for the robot and I need a way to make the torso smoolhly turn to face a target.

I've seen Align to Vector used in this fashion, but I don't remember exactly how it works. Anyone have any example for this?


Jeppe Nielsen(Posted 2006) [#2]
;Vector to target:
dx#=targetx#-robotx#
dy#=targety#-roboty#
dz#=targetz#-robotz#

;smooth variable:
smooth#=0.05

AlignToVector torsoentity,dx,dy,dz,3,smooth# <-assuming the z-axis is the torso's forward axis.



Hope this helps


Stevie G(Posted 2006) [#3]
.. or instead of aligntovector you could use ...

smooth = 0.05
turnentity torsoe, 0, deltayaw( torsoe , target )*smooth , 0

Stevie


Craig H. Nisbet(Posted 2006) [#4]
Hm, I hadn't thought of that.


jhocking(Posted 2006) [#5]
I cannot remember why, but it didn't work right when I tried using DeltaYaw once. I'm trying to remember, because it really seems like it should work. I think I'm going to try that again.

Anyway, I use AlignToVector. If you do, make sure to throw in a RotateEntity immediately afterward to make sure the character is the correct roll; sometimes the character flips over from AlignToVector.


mrjh(Posted 2006) [#6]
After reading this, I tried to use deltayaw in a game that I had already made where you tell different people where to go. The characters got close to where they where assigned to go, then went in circles around their destination.

How could I fix this?


DJWoodgate(Posted 2006) [#7]
Do a distance check.


mrjh(Posted 2006) [#8]
Sorry for not making this more clear, but I am already doing a distance chech.

Here is some of the code.
If EntityDistance(g\guy,g\gotopivot)>1
     TurnEntity g\guy,0,DeltaYaw(g\guy,g\gotopivot)/2,0
     MoveEntity g\guy,0,0,1
EndIf