I hope that you all are well! I have run into some issues while animating my character’s movement. As of right now, the code is:
if action_id == hash("left") then
facingleft = true
facingright = false
if action.pressed and facingleft and onground then
msg.post("#sprite", "play_animation", { id = hash("run") })
end
if action.released and onground then
msg.post("#sprite", "play_animation", { id = hash("idle") })
end
end
if action_id == hash("jump") then
jumping = true
onground = false
if action.pressed then
msg.post("#sprite", "play_animation", { id = hash("jumping") })
end
end
The problem with this is, if the player presses jump and left/right at the same time, and lands without releasing left/right, then the character gets stuck in the idle animation. This is, until left/right is released, and clicked again.
The problem is that you probably do not have any check for the situation when you land on the ground, in which you could set a proper animation - is it true? When you set onground to true?
Also, in first if you set facingleft to true and then you check for this in next if - it’s not needed.
I’m taking a look at my project and I think the onground variable is checked for. It is set to true when platypus returns GROUND_CONTACT.
The issue arises when only when I overlap inputs, like hold jump and left at the same time. If I were to release left once the character had landed, It works find from there. I will take a look into onground through, I’m sure I may have tripped up somewhere!
Recently I have run into another issue similar to the issues previously covered in this topic.
When pressing the right arrow key, the character moves right, as it should. Without letting go of the right arrow key, I press the attack button. After the attack animation is complete, it gets stuck on the “idle” animation, even though I am still holding the right arrow key. (attached is a video demonstration). https://forum.defold.com/uploads/default/original/3X/2/7/27745f284e4e5cc370422e10da72c13fa08bec51.mov
if action_id == ATTACK then
attackpause = true
sprite.play_flipbook("#sprite", "attack", function()
attackpause = false
end)
else
I am using platypus self.input_state to control movement as well as the animations.
local ground_contact = self.platypus.has_ground_contact()
if self.input_state[LEFT] then
self.platypus.left(ground_contact and 250 or 250)
play_animation(self, ground_contact and ANIM_RUN or ANIM_JUMP)
sprite.set_hflip("#sprite", true)
elseif self.input_state[RIGHT] then
self.platypus.right(ground_contact and 250 or 250)
play_animation(self, ground_contact and ANIM_RUN or ANIM_JUMP)
sprite.set_hflip("#sprite", false)
else
play_animation(self, ground_contact and ANIM_IDLE or ANIM_JUMP)
end
self.platypus.update(dt)
end
I think the issue might be routed in the above code, the last else statement where it plays the idle animation but I’m not sure what to do to fix it…