Ok, I’m trying to use triggers to know when an object is in range. So my tower has a collisionobject (trigger) and the enemy has a collision object (trigger). And it mostly works. But sometimes it just stops firing at the enemy (especially when there are many enemies).
Even if I don’t test for message.enter it will stop. But what is the best way to detect all objects inside of my collisionobject? Clearly I must be doing it wrong.
function on_message(self, message_id, message, sender)
if message_id == TRIGGER_RESPONSE then
print(message_id)
if message.enter and message.group == ENEMY then
self.inTargetZone = true
--fire missile55
self.target_id = message.other_id
fire_bullet(self)
elseif message.enter == false and message.group == ENEMY then
--reset turret to 0
self.inTargetZone = false
go.set_rotation(vmath.quat_rotation_z(0))
end
elseif message_id == hash("entity destroyed") and message.group == entmgr.enemies then
if self.target_id and message.entity == self.target_id then
self.target_id = nil -- Clear the target
-- Additional logic to handle lost target (e.g., redirect missile)
end
end
end