Movement Speed Fix Help

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
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Movement Speed Fix Help

Post by yetneverdone »

Hello fellow lovers, in my project, I have movement code like:

Code: Select all

player.x = player.x + player.speed * dt
Which works fine in my laptop (xubuntu)

But when I've tried it on another machine, windows desktop, the movement is slow compared to that of my laptop.

Any heads up on what should I consider?
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: Movement Speed Fix Help

Post by Beelz »

The problem lies in the hardware.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Movement Speed Fix Help

Post by yetneverdone »

Beelz wrote: Fri Mar 17, 2017 5:05 pm The problem lies in the hardware.
I think it is not ideal to conclude to that, because other parts of the gameplay works smooth, just the movement is not.
MasterLee
Party member
Posts: 141
Joined: Tue Mar 07, 2017 4:03 pm
Contact:

Re: Movement Speed Fix Help

Post by MasterLee »

Are you reacting on any mousemoved events? In haXe i noticed somethings goes slow when reacting on mouse move on Windows.
User avatar
DanielPower
Citizen
Posts: 50
Joined: Wed Apr 29, 2015 5:28 pm

Re: Movement Speed Fix Help

Post by DanielPower »

Can you post your code so we can see what is causing the issue?
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Movement Speed Fix Help

Post by yetneverdone »

MasterLee wrote: Fri Mar 17, 2017 5:20 pm Are you reacting on any mousemoved events? In haXe i noticed somethings goes slow when reacting on mouse move on Windows.
No, im just using the function

Code: Select all

 
function love.keypressed(key) 
love.keyboard.setkeyrepeat(true)
local dt = love.timer.getDelta()
if key == "d" then
player.x = player.x + player.spd + dt
end
end
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Movement Speed Fix Help

Post by zorg »

yetneverdone wrote: Sat Mar 18, 2017 5:15 am No, im just using the function

Code: Select all

 
function love.keypressed(key) 
love.keyboard.setkeyrepeat(true)
local dt = love.timer.getDelta()
if key == "d" then
player.x = player.x + player.spd + dt
end
end
One, you should multiply the speed with dt, not add dt to it.

Second, instead of doing this, why not just do:

Code: Select all

function love.update(dt)
    if love.keyboard.isDown('d') then
        player.x = player.x + player.spd * dt
    end
end
?
Also, that keyrepeat thing is unreliable; for example, it doesn't work on my computer because i disabled it. I wouldn't base any timing stuff on it.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Movement Speed Fix Help

Post by yetneverdone »

zorg wrote: Sat Mar 18, 2017 5:34 am
yetneverdone wrote: Sat Mar 18, 2017 5:15 am No, im just using the function

Code: Select all

 
function love.keypressed(key) 
love.keyboard.setkeyrepeat(true)
local dt = love.timer.getDelta()
if key == "d" then
player.x = player.x + player.spd + dt
end
end
One, you should multiply the speed with dt, not add dt to it.

Second, instead of doing this, why not just do:

Code: Select all

function love.update(dt)
    if love.keyboard.isDown('d') then
        player.x = player.x + player.spd * dt
    end
end
?

Oh. Im sorry. I meant to multiply that, just made a typo. Ive tried that in the update function, but for some reason, instead of the player moving, its teleporting
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Movement Speed Fix Help

Post by zorg »

yetneverdone wrote: Sat Mar 18, 2017 5:37 am Oh. Im sorry. I meant to multiply that, just made a typo. Ive tried that in the update function, but for some reason, instead of the player moving, its teleporting
It shouldn't. Post your project.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Movement Speed Fix Help

Post by yetneverdone »

zorg wrote: Sat Mar 18, 2017 5:40 am
yetneverdone wrote: Sat Mar 18, 2017 5:37 am Oh. Im sorry. I meant to multiply that, just made a typo. Ive tried that in the update function, but for some reason, instead of the player moving, its teleporting
It shouldn't. Post your project.
Ive tried doing that in the class Player update, in that it causes the teleportation. After trying it on the main love.update, it works.

IDK why is that. Anyways thanks for the help. Ill check later if it fixes the issue with the window machine
Post Reply

Who is online

Users browsing this forum: No registered users and 80 guests