Hi, i’m a beginner with Defold and i try to make my first game with it.
My game is a one way platformer game (like mario run) and my probelm is that i don’t know how to create a simple AI enemy who avoid the trap etc… I already try some way with 2 trigger attached to my enemy and when the trigger enter in collision with an “danger” objet it send a message to my enemy and the enemy go to the opposite. But it doesn’t work !
There is my trigger script:
function on_message(self, message_id, message, sender)
if message_id == hash("trigger_response")then
if message.group == hash("danger")then
msg.post("mechant/mechant#script", "triggerD")
end
end
end
and here is a part of my enemy script :
function update(self, dt)
self.velocity.x = -speedX
if triggerG == 1 and self.velocity.x == -speedX then
self.velocity.x = speedX
triggerG =0
elseif triggerD == 1 and self.velocity.x == speedX then
self.velocity.x = -speedX
triggerD = 0
end
...
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
if message.group == hash("solide") then
handle_geometry_contact(self, message.normal, message.distance)
elseif message.group == hash("danger") then
self.velocity.y = 400
speedX = 10
msg.post("#collisionobject", "disable")
end
elseif message_id == hash("triggerG")then
triggerG = 1
elseif message_id == hash("triggerD")then
triggerD = 1
end
end
I haven’t forget to add “trigger” and “danger” in my enemy object and danger object so i think the problem is in the script.
here’s my enemy collection with the trigger left and right and the enemy
(I’m sorry if i have do some mystake i’m not English)