Here is a little patch until wrightmat fixes the problem. The hero will not float and get stuck on the jumping animation. Although, it will not prevent the hero from standing still and moving when the right/down or left/down is being pressed at the same time.
Wrightmat's sidescroller script:
hereWrightmat's monster script:
hereI think I heard a key on_pressing function was being made. Maybe that could fix the problem.
Patch for game:on_started(): function game:on_started()
local hero = game:get_hero()
hero:set_tunic_sprite_id("main_heroes/eldran")
sol.timer.start(gravity, function()
if self:get_map() ~= nil then
-- Gravity: move entities down one pixel on every update if there's no collision.
-- (like with the ground or a platform) and hero not jumping or on a ladder.
local hero = self:get_hero()
local x, y, l = hero:get_position()
if state ~= "jumping" and self:get_map():get_ground(hero:get_position()) ~= "ladder" then
if not hero:test_obstacles(0, 1) then hero:set_position(x, (y + 1), l) end
elseif state == "jumping" then
for i = 1, jump_height do
if not hero:test_obstacles(0, -1) then hero:set_position(x, (y - 1), l) end
end
sol.timer.start(gravity * jump_height, function()
if self:is_command_pressed("right") or self:is_command_pressed("left") then
state = "walking"
else
state = "stopped"
end
--right
if self:is_command_pressed("right") and self:is_command_pressed("left") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
if self:is_command_pressed("right") and self:is_command_pressed("up") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
--left
if self:is_command_pressed("left") and self:is_command_pressed("right") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
if self:is_command_pressed("left") and self:is_command_pressed("up") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
--up
if self:is_command_pressed("up") and self:is_command_pressed("right") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
if self:is_command_pressed("up") and self:is_command_pressed("left") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
if self:is_command_pressed("up") and self:is_command_pressed("down") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
end)
hero:set_animation(state)
end
function game:on_key_pressed(key)
local hero = game:get_hero()
if key == "up" and key == "down" and key == "left" and key == "right" then
hero:set_animation("walking")
else
hero:set_animation("walking")
end
end
Explanation:I added some checks function game:on_started() to prevent the hero from floating around.
--right
if self:is_command_pressed("right") and self:is_command_pressed("left") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
if self:is_command_pressed("right") and self:is_command_pressed("up") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
--left
if self:is_command_pressed("left") and self:is_command_pressed("right") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
if self:is_command_pressed("left") and self:is_command_pressed("up") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
--up
if self:is_command_pressed("up") and self:is_command_pressed("right") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
if self:is_command_pressed("up") and self:is_command_pressed("left") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
if self:is_command_pressed("up") and self:is_command_pressed("down") then
hero:set_animation("walking")
state = "walking"
else
state = "stopped"
end
I added this function to prevent the hero from being stuck on the jumping animation.
function game:on_key_pressed(key)
local hero = game:get_hero()
if key == "up" and key == "down" and key == "left" and key == "right" then
hero:set_animation("walking")
else
hero:set_animation("walking")
end
end