Page 1 of 1

Player stopping movement but moving incredibly slowly afterwards.

Posted: Tue Feb 25, 2025 6:21 pm
by fennx1000
I have a player that stops moving when it goes outside the screen, this is how it is meant to be however there is a problem because the player suddenly becomes really slow after being unpaused and it does not seem to be fixing. Here is the code.


Player = {}
Player.speed = 400
Player.health = 3
Player.stop = false
Player.__index = Player

function Player:New(x,y,world)
local this={
x=x,
y=y,
r=0,
body = love.physics.newBody(world, x, y, "dynamic"),
shape = love.physics.newCircleShape(20)
}
this.shape = love.physics.newCircleShape(20)
this.fixture = love.physics.newFixture(this.body, this.shape)

setmetatable(this, self)
return this
end

function Player:Update(dt)
if Player.stop then
self.body:setLinearVelocity(0,0)
end

if love.mouse.isDown(1) then
local x, y = love.mouse.getPosition()
local dx = x - self.body:getX()
local dy = y - self.body:getY()
local angle = math.atan2(dy, dx)
self.body:setAngle(angle)
self.body:applyForce(-Player.speed * math.cos(angle), -Player.speed * math.sin(angle))
end
end

function Player:render()
love.graphics.setColor(3/255, 252/255, 11/255)
love.graphics.circle("fill", self.body:getX(), self.body:getY(), self.shape:getRadius())
end

Re: Player stopping movement but moving incredibly slowly afterwards.

Posted: Wed Feb 26, 2025 2:33 pm
by dusoft