Movement Too Fast

I made it so when I press a button, the red slime in the middle moves (ignore the other slimes and the health bars), but as you can see, the movement is very fast, which I don’t like. How do I make the movement slower?
Here’s the code:

function init(self)
	msg.post(".", "acquire_input_focus") -- <1>
	self.vel = vmath.vector3() -- <2>   
	Taking_Damage = 0
end

function update(self, dt)
	local pos = go.get_position() -- <3>
	pos = pos + self.vel * dt -- <4>
	go.set_position(pos) -- <5>

	self.vel.x = 0 -- <6>
	self.vel.y = 0
end

local Death = false

function on_input(self, action_id, action)
	if action_id == hash("Test Run") and Death == false then
		self.vel.x = -21000

end
end

That is 21000 pixels/s.

If you’re saying it’s 21000 pixels per second, I don’t know what to do, because if I lower the number, the number of pixels it moves is less; how would I lower the speed but also make it move the same distance

You are setting the velocity to zero at the end of the update function which means that it only moves for a single frame. Do not set the velocity to zero and decrease the speed.

Might I also suggest using the go.animate function for this sort of movement.

local pos = go.get_position()
go.animate(".", "position.x", go.PLAYBACK_ONCE_FORWARD, pos.x - 350, go.EASING_INOUTSINE, 1)

Use the power of the engine to do it for you. This function can animate various other things automatically for you. Much easier than doing it manually.

5 Likes

Thank you! Works perfectly.

2 Likes