I know for a fact that this question has been asked before, I've even found a tutorial. Unfortunately my numbers are coming back weird.
Here's my situation. I have an object whom's speed is determined by velocity variables (forward, strafe, and upward). I'm using the 'move object <speed>' function which moves the object forward based on its orientation.
What I need is the angular offsets of the velocities to change the direction of the 'move object' function (Rotations X and Y). I need to use the single move-object function to cohort with Object Collision.
Here's the code I've found on a tutorial on this site:
r = make vector3(1) : `Current direction
r = make vector3(2) : `Direction you want him to face
`Set vectors
set vector3 1, 10, -5, 3 : `Current direction = (10, -5, 3)
set vector3 2, -5, 10, -2 : `Target direction = (-5, 10, -2)
`What's the angle we want him to face?
normalize vector3 1, 1 : `Normalize vector 1
normalize vector3 2, 2 : `Normalize vector 2
angle# = acos(dot product vector3(1, 2))
`Display on screen
print "The angle between the two vectors is ", angle#, " degrees."
It's to my understanding that substituting 'acos' with 'asin' will get me the other angle I need
Here's my code
r=make vector3(1)
r=make vector3(2)
set vector3 1,0,0,0
set vector3 2,sVelocity#,uVelocity#,fVelocity#
normalize vector3 1,1
normalize vector3 2,2
dot#=dot product vector3(1,2)
sxo#=asin(dot#)
syo#=acos(dot#)
Unfortunately when presenting the dot product with a vector that's 0,0,0, the returns are non-responsive. When I add '1' to all coordinates, it returns information but it seems to be very wrong.
My rotate object/move code
rem sx# and sy# are the originals, sxo# and syo# are the offsets
rotate object PlayerObject,sx#+sxo#,sy#+syo#,sz#
move object PlayerObject,sqrt(fVelocity#^2+sVelocity#^2+uVelocity#^2)