I'm trying to make a vine entity that can only be destroyed by using fire. There's no error, but the entity doesn't get destroyed when fire is used. local entity = ...
local map = entity:get_map()
function entity:on_created()
self:set_size(16, 16)
self:set_traversable_by("hero", false)
self:create_sprite("entities/bush_vine")
if entity:get_type() == "fire" then
sol.audio.play_sound("jump")
self:remove()
end
end
function entity:on_removed()
self:get_sprite():set_animation("destroy")
end
I would try to use dynamic tiles ???
I think you missed the collision test, because in your code, you put:
function entity:on_created()
self:set_size(16, 16)
self:set_traversable_by("hero", false)
self:create_sprite("entities/bush_vine")
-- Problem is here : you ask if the entity you created is "fire", but not if it's colliding with fire.
if entity:get_type() == "fire" then
...
end
I guess it should be (not tested):
function entity:on_created()
self:set_size(16, 16)
self:set_traversable_by("hero", false)
self:create_sprite("entities/bush_vine")
-- Don't know what type of collision use, I think I would put "overlapping" because you want the fire to be on the vine
entity:add_collision_test("overlapping", function(me, other)
if other:get_type() == "fire" then
sol.audio.play_sound("jump")
me:remove()
end
end)
...
Yes, there is no collision and no set_traversable_by rules so nothing can collide with
@MetalZelda : Line 6 of the original code, there is the set_traversable_by rules :)
Quote from: Renkineko on March 11, 2016, 07:41:33 AM
@MetalZelda : Line 6 of the original code, there is the set_traversable_by rules :)
Oh yes, my mistake, I didn't see it :o