With functions in my lib:
Code:
// Angle between 2 vectors, given in radians
function Angle(src,dest: single): single;
begin
result:=src-dest;
while result<-PI do result:=result+PI*2;
while result>PI do result:=result-PI*2;
end;
// By pythagoras a^2+b^2=c^2 you don't need Sqrt() to determine the equality
function PointInCircle(const p,circle: TVector2f; const radius: single): boolean;
var x,y: single;
begin
x:=circle.x-p.x; y:=circle.y-p.y;
PointInCircle:=(x*x+y*y)<(radius*radius);
end;
And knowing the angle_delta that is half of pie's slice angle, we can count if point is between them:
Code:
if PointInCircle(beam.position, player.position, radius) then
if abs(Angle(beam.angle, angle_from_beam_to_player)) < angle_delta then begin
Collide;
end;
You can also use this for the angle from beam to player:
Code:
function Angle(const px1,py1,px2,py2: single): single;
begin
result:=arctan2(py2-py1,px2-px1);
if result<0 then result:=result+PI*2;
end;
Bookmarks