Player stopping movement but moving incredibly slowly afterwards.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
fennx1000
Prole
Posts: 1
Joined: Tue Feb 25, 2025 6:18 pm

Player stopping movement but moving incredibly slowly afterwards.

Post 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
User avatar
dusoft
Party member
Posts: 754
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Player stopping movement but moving incredibly slowly afterwards.

Post by dusoft »

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 8 guests