How can I make a dash/charge? (SOLVED)

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 :slight_smile:
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

Sorry, can I delete this topic? :slight_smile:

If you have a solution you should post it to help others who might have a similar problem in the future.

I’m a little shy, because my code is not very good. :slight_smile: Anyway, here it is:

PLAYER_SPEED_START = 250
PLAYER_SPEED = PLAYER_SPEED_START
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
        self.roll = false  --cheсk roll or not
	self.rollTimer = 0.5 --durability of roll
end

function update(self, dt)
        local pos = go.get_position() 
	pos = pos + self.vel * dt 
	go.set_position(pos)

        if self.roll then --if we rolling now
		self.rollTimer = self.rollTimer - dt --start timer
		play_animation(self, hash("player_roll")) --play roll animation
	end

	if self.rollTimer < 0 then --if we end rolling
		self.roll = false
		self.rollTimer = 0.5 --return timer
		PLAYER_SPEED = PLAYER_SPEED_START --assign normal speed to player
	end

	self.vel.x = 0 
	self.vel.y = 0

	self.moving = false
end

function on_input(self, action_id, action)
              if action_id == hash("roll_button") and action.released then
				if not self.roll then --if we not rolling
				PLAYER_SPEED = 1.5 * PLAYER_SPEED --increase speed for roll
				self.roll = true
			end
end
4 Likes

They see me rollin’

THEY HATIN.

2 Likes