Makkeonmies
Member
In my top-down action game I want to have it checked if an enemy is behind the player. does collision_line() work here, or only to check for objects in front?
if collision_line(x, y, direction-180, direction-180, enemypar, false, false) //do stuff
// Is there an enemy behind me 32 pixels away?
var x2 = x + lengthdir_x(32, direction - 180);
var y2 = y + lengthdir_y(32, direction - 180);
var enemy = collision_line(x, y, x2, y2, enemypar, false, false);
if (instance_exists(enemy))
{
// Stuff
}
big thanks. completely forgot about lengthdir . Ill try this one out when i get to go back to my project!collision line takes 4 coordinates. You gave it the x1 and y1 arguments, but not the x2 and y2 arguments. Something like this should do what you want:
So just to clarify, you're checking a collision line behind you, 32 pixels away, for any child of enemypar. If an instance exists, you have its ID saved in enemy. If there will be lots of enemies (think of zombies chasing you) you can use collision_line_list to get all of their IDs in a list and then you loop through that list.GML:// Is there an enemy behind me 32 pixels away? var x2 = x + lengthdir_x(32, direction - 180); var y2 = y + lengthdir_y(32, direction - 180); var enemy = collision_line(x, y, x2, y2, enemypar, false, false); if (instance_exists(enemy)) { // Stuff }
works fine indeed. big thanks @Bentley !! also @Nidoking @Sabnock !collision line takes 4 coordinates. You gave it the x1 and y1 arguments, but not the x2 and y2 arguments. Something like this should do what you want:
So just to clarify, you're checking a collision line behind you, 32 pixels away, for any child of enemypar. If an instance exists, you have its ID saved in enemy. If there will be lots of enemies (think of zombies chasing you) you can use collision_line_list to get all of their IDs in a list and then you loop through that list.GML:// Is there an enemy behind me 32 pixels away? var x2 = x + lengthdir_x(32, direction - 180); var y2 = y + lengthdir_y(32, direction - 180); var enemy = collision_line(x, y, x2, y2, enemypar, false, false); if (instance_exists(enemy)) { // Stuff }