Hi everyone! I’m make bullethell-game, in which the player can walk in 8 directions. And I want to make character roll, like in enter the gungeon. But I do not know how to do it. I looked at the forum and did not find the answer.
Do you have any ideas?
Thank you
Movement code here:
function init(self)
msg.post(".", "acquire_input_focus")
self.vel = vmath.vector3()
self.dir = vmath.vector3(0, 1, 0)
self.current_animation = nil
self.moving = false
end
function update(self, dt)
local pos = go.get_position()
pos = pos + self.vel * dt
go.set_position(pos)
if (self.vel.x == 0 and self.vel.y == 0) then
play_animation(self, hash("player_idle"))
end
end
function on_input(self, action_id, action)
if action_id then
if action_id == hash("left_stick_click") then
elseif action_id == hash("left_stick_left") or action_id == hash("left_pad_left") then
play_animation(self, hash("player_walk"))
sprite.set_hflip("#playerSprt", true)
self.vel.x = -PLAYER_SPEED * action.value
elseif action_id == hash("left_stick_right") or action_id == hash("left_pad_right") then
play_animation(self, hash("player_walk"))
sprite.set_hflip("#playerSprt", false)
self.vel.x = PLAYER_SPEED * action.value
elseif action_id == hash("left_stick_up") or action_id == hash("left_pad_up") then
self.vel.y = PLAYER_SPEED * action.value
play_animation(self, hash("player_walk"))
elseif action_id == hash("left_stick_down") or action_id == hash("left_pad_down") then
self.vel.y = -PLAYER_SPEED * action.value
play_animation(self, hash("player_walk"))
--right stick
elseif action_id == hash("right_stick_click") then
elseif action_id == hash("right_stick_left") then
elseif action_id == hash("right_stick_right") then
elseif action_id == hash("right_stick_up") then
elseif action_id == hash("right_stick_down") then
elseif action_id == hash("right_pad_left") and action.pressed then
self.firing = true
end
end
if vmath.length(self.vel) > 0 then
self.dir = vmath.normalize(self.vel)
end
end