Solthall
Member
Hello.
I'm trying to create a cone of vision for my enemy object. I am able to draw the cone I want:
Create event:
coneOfSightLeft = 45;
coneOfSightRight = -45;
coneOfSightLength = 600;
Draw event:
draw_triangle(x, y, x+lengthdir_x(coneOfSightLength,coneLeft), y+lengthdir_y(coneOfSightLength,coneLeft), x+lengthdir_x(coneOfSightLength,coneRight), y+lengthdir_y(coneOfSightLength,coneRight), false);
draw_set_alpha(0.1);
I want to check for the player object using the point_in_triangle function. Haven't used that before so after messing arround with it I just cant get the point_in_triangle to correspond with the cone I have drawn!
It should be something like this:
Step event:
var player = instance_nearest(x, y, obj_player);
if instance_exists(player)
{
var x1 = x + lengthdir_x(?); //what to put in here to replicate the shape and size of the drawn vision cone
var y1 = y + lengthdir_y(?);
var x2 = x + lengthdir_x(?);
var y2 = y + lengthdir_y(?);
if point_in_triangle(player.x, player.y, x, y, x1, y1, x2, y2)
{
can_see = true;
}
else
{
can_see = false;
}
}
I'm trying to create a cone of vision for my enemy object. I am able to draw the cone I want:
Create event:
coneOfSightLeft = 45;
coneOfSightRight = -45;
coneOfSightLength = 600;
Draw event:
draw_triangle(x, y, x+lengthdir_x(coneOfSightLength,coneLeft), y+lengthdir_y(coneOfSightLength,coneLeft), x+lengthdir_x(coneOfSightLength,coneRight), y+lengthdir_y(coneOfSightLength,coneRight), false);
draw_set_alpha(0.1);
I want to check for the player object using the point_in_triangle function. Haven't used that before so after messing arround with it I just cant get the point_in_triangle to correspond with the cone I have drawn!
It should be something like this:
Step event:
var player = instance_nearest(x, y, obj_player);
if instance_exists(player)
{
var x1 = x + lengthdir_x(?); //what to put in here to replicate the shape and size of the drawn vision cone
var y1 = y + lengthdir_y(?);
var x2 = x + lengthdir_x(?);
var y2 = y + lengthdir_y(?);
if point_in_triangle(player.x, player.y, x, y, x1, y1, x2, y2)
{
can_see = true;
}
else
{
can_see = false;
}
}