So, Hello everybody! In my platformer game I have different entities that need detection code in their behaviour like The Tower with Ranged Attack, so I wonder which function is it better to use to do that? This is what I personally do as a beginner:
So the question relates to the code with collision_ractangle function: is there any better way of detecting objects in range than that?
Edit: Found a mistake in the code
GML:
attack_cooldown+=attack_speed;
if(floor(attack_cooldown)>=attack_time)
{
var in_range = ds_list_create();
var front_range = attack_front_range;
var back_range = attack_back_range;
if(image_xscale = -1)
{
front_range = attack_back_range;
back_range = attack_front_range
}
var number_in_range = collision_rectangle_list(x- back_range,FLOOR_Y - 55,x+front_range,FLOOR_Y,enemy_parent,0,true,in_range,0);
//Here I could have collision_rectangle instead, so just instead
//Instead of ds_list it would return just one instance
if(number_in_range = 0)
{
ds_list_destroy(in_range);
return noone
}
else return in_range
}
else return noone
Edit: Found a mistake in the code
Last edited: