Hello, in my game i have a character that can launch a fireball (called “power” in my game) at enemies. My problem is that i have tried many way to msg.post from my “power” object to my “enemie” object, but the “enemie” object never receive the message. I know the collision between the two do happend because my “power” object play his explosion animation and delete itself, but the enemie object didn’t react.
There’s my “power” object script :
go.property("degat", 20)
function init(self)
self.t = 2 --temps de vie
self.explode = 0 --exploser ou pas
self.enter = 0 --contact
self.velocity = vmath.vector3(0, 0, 0)
end
function update(self, dt)
self.t = self.t - dt
if self.t < -(8/12) then --animation explosion finis, suppression
go.delete()
elseif self.t <= 0 and self.explode == 0 then --distance max atteinte ou contact, animation explosion
msg.post("#sprite", "play_animation", {id = hash("explosion4")})
self.explode = 1
elseif self.t < 2-(8/12) and self.explode == 0 then --animation de charge finis, boule de feu lancer
self.velocity = vmath.rotate(go.get_rotation(), vmath.vector3(0,-15,0))
go.set_position(go.get_position() + self.velocity)
end
end
function on_message(self, message_id, message, sender)
if message_id == hash ("contact_point_response") then
msg.post(message.other_id, "damage", {degat = self.degat})
if self.enter == 0 then
self.t = 0.05 --contact, declenche explosion prématuré
self.enter = 1
end
end
end
and there’s my “enemie” object script (for the moment he don’t move or anything but that doesn’t change anything) :
go.property("niveau", 1)
function init(self)
self.live = math.floor(150 * 1.309 ^ (self.niveau - 1)) --augmente vie en fonction du niveau (25 000 max au niveau 20)
self.degat = math.floor(15 * 1.225 ^ (self.niveau - 1)) --augmente degat en fonction du niveau (710 max au niveau 20)
self.speed = math.floor(300 * 1.016 ^ (self.niveau - 1)) --augmente vitesse en fonction du niveau (405 max au niveau 20)
end
function update(self, dt)
if self.live <= 0 then
go.delete()
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("damage") then
self.live = self.live - message.degat
end
end