G
Grim Xavier
Guest
So I have a problem with the way my turret targets enemies. currently it checks to see if there's an enemy 750 pixels in front of it, and then attacks that enemy. Here's the code:
if collision_rectangle(x, y-96, x-750, y+32, obj_enemyParent, false, true) {
var stoneAttack
stoneAttack = instance_create(x, y-50, obj_stoneAttack) with (stoneAttack) {
direction = point_direction(x, y, obj_enemyParent.x, obj_enemyParent.y)
}
The problem is that if there's an enemy inside the collision box AND an enemy outside of the collision box at the same time, the turret could very well attack the enemy outside of the collision box, no matter where it is. This is because, as the code reads now, if there's an enemy in the collision box, the turret will target ANY enemy. How do I specify to only attack enemies that walk into this collision box? Any ideas would be greatly appreciated.
if collision_rectangle(x, y-96, x-750, y+32, obj_enemyParent, false, true) {
var stoneAttack
stoneAttack = instance_create(x, y-50, obj_stoneAttack) with (stoneAttack) {
direction = point_direction(x, y, obj_enemyParent.x, obj_enemyParent.y)
}
The problem is that if there's an enemy inside the collision box AND an enemy outside of the collision box at the same time, the turret could very well attack the enemy outside of the collision box, no matter where it is. This is because, as the code reads now, if there's an enemy in the collision box, the turret will target ANY enemy. How do I specify to only attack enemies that walk into this collision box? Any ideas would be greatly appreciated.