GLBasic at the moment doesn't recognise the command...
ATAN = ATAN2
That's right! :good:
Should have noticed that :)
The angle between points is correct now (up is 270 degrees) :
FUNCTION angleBetweenPoints:ax,ay,ex,ey
LOCAL angle
angle=ATAN(ey-ay,ex-ax)
IF angle<0.0
angle=180.0+(180.0+angle)
ENDIF
RETURN angle
ENDFUNCTION
is it the same with x & z?
angle=ATAN(ez-az,ex-ax)
To use the 2 angles together for (x, y, z) <--> (ax, ay, az)
Yes, indeed.
thats simple :D
DRAWRECT 0,0,20,20, RGB(0xff, 0x00, 0x00)
DRAWRECT 0,10,10,1, RGB(0x00, 0x00, 0x00)
GRABSPRITE 1, 0,0,20,20
BLACKSCREEN
TYPE TPlayer
x%;y%
angle#
lookat_handle% = -1
ENDTYPE
GLOBAL TPlayers[] AS TPlayer
LOCAL Player1 = CreatePlayer(20,20)
LOCAL Player2 = CreatePlayer(100,100)
PlayerLookAt(Player1,Player2)
WHILE TRUE
DrawAll()
SHOWSCREEN
WEND
END
FUNCTION CreatePlayer%: x, y
LOCAL t AS TPlayer
t.x = x
t.y = y
DIMPUSH TPlayers[], t
RETURN LEN(TPlayers[])-1
ENDFUNCTION
FUNCTION PlayerLookAt: player, target
TPlayers[player].lookat_handle = target
ENDFUNCTION
FUNCTION DrawAll:
FOREACH t IN TPlayers[]
IF t.lookat_handle > -1
t.angle = 180-ATAN(TPlayers[t.lookat_handle].y - t.y, TPlayers[t.lookat_handle].x - t.x)
ENDIF
ROTOSPRITE 1, t.x, t.y, t.angle
NEXT
ENDFUNCTION