Hawkblood, I don't think that quite solves my problem, but thank you. Atanfull is 0-360.
This is the code I'm using:
`Start up
cls
sync on
sync rate 30
`3d locations
dim x(3)
dim y(3)
dim z(3)
`3 box objects
make object box 1, 50,50,100
make object box 2, 50,50,50
make object box 3, 50,50,50
`reposition 2 of them
position object 2, -100, 0, -100
position object 3, -200, 0, - 150
do
`record positions of all 3 objects
x(1) = object position x(1)
y(1) = object position y(1)
z(1) = object position z(1)
x(2) = object position x(2)
y(2) = object position y(2)
z(2) = object position z(2)
x(3) = object position x(3)
y(3) = object position y(3)
z(3) = object position z(3)
`Perspective camera view
position camera x(1)+200, y(1)+200, z(1)+200
point camera x(1),y(1),z(1)
`Show angle
text 0,10, "angle = " + str$(angle)
`Get an angle reading at point 0,0,0 for positon x and z of object 2
angle = ATANFULL(x(2), z(2))
`Rotate object 1 at a curveangle equating to ATANFULL
yrotate object 1,curveangle(angle, object angle y(1), 4)
`Control 'Waypoint'
if upkey() = 1 then move object 2,10
if downkey() = 1 then move object 2,-10
`Control 'Object 1'
if inkey$() = "w" then move object 1,10
if inkey$() = "s" then move object 1,-10
sync
loop
[Just for testing]
If I press up and down, it'll move the 'waypoint' object, and the AI object will happily watch it. If I move the AI object with 'w and s', it won't continue facing the waypoint.
'ATANFULL' is reading the angle between X and Y from a point, which is 0,0,0
What I want it to do is read the angle between X and Y from any point in space.
[EDIT]
In theory, I've solved the problem...now to put it to practice
In ATANFULL, I subtracted the object position values from the waypoint position values, so in essence, I get this:
angle = ATANFULL( x(2) -x(1), z(2) - z(1))
So now, for the angle to turn smoothly for each way point, I need a curvevalue, which should work.
Amended (working) code:
Rem Project: Trigonometry
Rem Created: Wednesday, August 18, 2010
Rem ***** Main Source File *****
`Start up
cls
sync on
sync rate 30
`3d locations
dim x(3)
dim y(3)
dim z(3)
`3 box objects
make object box 1, 50,50,100
make object box 2, 50,50,50
make object box 3, 50,50,50
`reposition 2 of them
position object 2, -100, 0, -100
position object 3, -200, 0, - 150
do
`record positions of all 3 objects
x(1) = object position x(1)
y(1) = object position y(1)
z(1) = object position z(1)
x(2) = object position x(2)
y(2) = object position y(2)
z(2) = object position z(2)
x(3) = object position x(3)
y(3) = object position y(3)
z(3) = object position z(3)
`Perspective camera view
position camera x(1)+200, y(1)+200, z(1)+200
point camera x(1),y(1),z(1)
`Show angle
text 0,10, "angle = " + str$(angle)
`xoffset = sin(x(2))
`yoffset = -cos(z(2))
angle = ATANFULL( x(2) -x(1), z(2) - z(1))
`Rotate object 1 at a curveangle equating to ATANFULL
yrotate object 1,curveangle(angle, object angle y(1), 4)
`Control 'Waypoint'
if upkey() = 1 then move object 2,10 : move object 1, 10
if downkey() = 1 then move object 2,-10 : move object 1, 10
if leftkey() = 1 then turn object left 2,5
if rightkey() = 1 then turn object right 2,5
sync
loop
[EDIT2]
It works in my game too. Huzzah.
Cheers.
Click!
