Forum
CS2D Scripts [Lua Question] Calculate Aim Angle[Lua Question] Calculate Aim Angle
10 replies 1
1
2
3
4
5
6
7
2
3
4
5
6
7
player1_x = 36 player_1_y = 65 player2_x = 67 player2_y = 53 angle = math.atan2((player1_y-player2_y),(player1_x-player2_x))
Thanks a lot, are the positions in tiles?
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
function FindAngle(fx,fy,tx,ty) 	-- Angle found 	local Angle = math.deg(math.atan2(fy-ty,fx-tx) - (math.pi/2)) 	-- Fix the Angle 	if Angle < -180 then Angle = Angle + 360 end 	-- Return it 	return Angle end
It returns the angle using the CS2D Rotation in degrees, (-180 to 180)
And the positions are in pixels. (I didn't test if works with tiles, i think yes)
its like if i used x: 1000 and y: 1000 (player position)
and
its like if i used x: 10 and y: 10 (a tile position)
both calculations would be correct, just return different result
and ofcoutrse it would return center of tile, as you then use tile in calculation, not x y of player
lol lee stop trolling
1