samspade
Member
I have a targeting system which functions a little like the following:
Loop through all of a certain object class
if is within a certain distance
if is within a certain angle
add it to a priority queue based on distance
Actual code is:
The basic idea is that I get a subset of targets sorted by distance.
The problem with this is that it is detecting angle based on a target's x and y (center of sprite). There's no issue with this for small sprites, but with large sprite sprites, especially with narrow angle, you can be pointing at an instance but that actual x/y of the instance won't be within the angle so you can't target it.
I need a good way to check if the angle is right against the sprite itself rather than the x/y. Right now the only solution I can think of to add two line collision checks on the outside of the 'cone' of vision or to create a cone mask, scale it, and use precise collision checking.
Loop through all of a certain object class
if is within a certain distance
if is within a certain angle
add it to a priority queue based on distance
Actual code is:
Code:
with (destroyable_parent) {
//check if in range
var _dist_to_player = point_distance(xx, yy, x, y);
if (_dist_to_player > other.max_range) continue;
//check if in right angle
var _direction_to_enemy = point_direction(xx, yy, x, y);
if (abs(angle_difference(_direction_to_enemy, player_angle)) > other.max_angle) continue;
//add to queue based on distance
ds_priority_add(_target_priority_queue, id, _dist_to_player);
}
The problem with this is that it is detecting angle based on a target's x and y (center of sprite). There's no issue with this for small sprites, but with large sprite sprites, especially with narrow angle, you can be pointing at an instance but that actual x/y of the instance won't be within the angle so you can't target it.
I need a good way to check if the angle is right against the sprite itself rather than the x/y. Right now the only solution I can think of to add two line collision checks on the outside of the 'cone' of vision or to create a cone mask, scale it, and use precise collision checking.