Problems with slow movement speeds

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.
placeholder
Prole
Posts: 13
Joined: Mon Mar 15, 2021 9:00 pm

Re: Problems with slow movement speeds

Post by placeholder »

darkfrei wrote: Tue Mar 16, 2021 3:19 pm
You can round your position after the moving, when the player don't press keys anymore. So the diagonal movement will be pretty smooth
This is what i'm doing in example 2, and the movement is not smooth. Is there something wrong with how i coded example 2?
User avatar
darkfrei
Party member
Posts: 1196
Joined: Sat Feb 08, 2020 11:09 pm

Re: Problems with slow movement speeds

Post by darkfrei »

placeholder wrote: Tue Mar 16, 2021 3:30 pm
darkfrei wrote: Tue Mar 16, 2021 3:19 pm
You can round your position after the moving, when the player don't press keys anymore. So the diagonal movement will be pretty smooth
This is what i'm doing in example 2, and the movement is not smooth. Is there something wrong with how i coded example 2?
I see the problem that you make x=x+dt*speed, but the minus by the y.
Also speed_x can be not same as speed_y.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
placeholder
Prole
Posts: 13
Joined: Mon Mar 15, 2021 9:00 pm

Re: Problems with slow movement speeds

Post by placeholder »

darkfrei wrote: Tue Mar 16, 2021 3:35 pm
I see the problem that you make x=x+dt*speed, but the minus by the y.
Also speed_x can be not same as speed_y.
y is minus so that the rectangle moves upwards instead of down. this is not a problem.

speed_x and speed_y do not exist in the example so i'm not sure what you mean, and an object can certainly move in more than one direction with a single speed variable.

how -SPECIFICALLY - do i adjust example 2 to make the movement smooth?
User avatar
darkfrei
Party member
Posts: 1196
Joined: Sat Feb 08, 2020 11:09 pm

Re: Problems with slow movement speeds

Post by darkfrei »

placeholder wrote: Tue Mar 16, 2021 3:39 pm
darkfrei wrote: Tue Mar 16, 2021 3:35 pm
I see the problem that you make x=x+dt*speed, but the minus by the y.
Also speed_x can be not same as speed_y.
y is minus so that the rectangle moves upwards instead of down. this is not a problem.

speed_x and speed_y do not exist in the example so i'm not sure what you mean, and an object can certainly move in more than one direction with a single speed variable.

how -SPECIFICALLY - do i adjust example 2 to make the movement smooth?
I've updated this comment:
viewtopic.php?f=4&t=90455#p239262
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
placeholder
Prole
Posts: 13
Joined: Mon Mar 15, 2021 9:00 pm

Re: Problems with slow movement speeds

Post by placeholder »

darkfrei wrote: Tue Mar 16, 2021 3:40 pm
I've updated this comment:
viewtopic.php?f=4&t=90455#p239262
I'm not sure what specific update you made to the comment, or what specifically you intended to clarify.

It seems that your suggested solution is to run a conditional if statement on every frame for every moving object to determine if the buffer is large enough to be rounded safely. that's what the buffer is, right? is this the best solution? it seems janky.

is the buffer system your suggested solution? is there anything else i can do with the mathematics in example 2 to fix this problem instead of using the buffer?

also, why does example 2 not work? other posters also suggested the solution that i tried to implement in example 2, but it's causing stuttery movement. did i code example 2 wrong? am i misunderstanding? why is example 2 not working?
User avatar
darkfrei
Party member
Posts: 1196
Joined: Sat Feb 08, 2020 11:09 pm

Re: Problems with slow movement speeds

Post by darkfrei »

placeholder wrote: Tue Mar 16, 2021 3:52 pm
also, why does example 2 not work? other posters also suggested the solution that i tried to implement in example 2, but it's causing stuttery movement. did i code example 2 wrong? am i misunderstanding? why is example 2 not working?
rect.draw_y = math.floor(rect.y - 0.5) -- not sure, but you use negative y;

Also please test the code with positive y, maybe your error is here.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
placeholder
Prole
Posts: 13
Joined: Mon Mar 15, 2021 9:00 pm

Re: Problems with slow movement speeds

Post by placeholder »

darkfrei wrote: Tue Mar 16, 2021 4:32 pm
rect.draw_y = math.floor(rect.y - 0.5) -- not sure, but you use negative y;

Also please test the code with positive y, maybe your error is here.
subtracting y makes the rectangle move upwards instead of downwards.

changing this does not help, as you can see be running the code below, which contains your suggested changes. this is not helpful

do you have any other suggestions, hopefully suggestions that you test by running the code before making the suggestion?

Code: Select all

push = require "push"
screenWidth = 160
screenHeight = 120
push:setupScreen(screenWidth, screenHeight, screenWidth * 4, screenHeight * 4)
io.stdout:setvbuf("no")

-- please set EXAMPLE to 1 or 2
-- 1 generates smooth diagonal movement, but breaks if rect.speed is set to 25-ish or below
-- 2 works at slow speed, but generates stuttery movement at all speeds FOR SOME REASON??

EXAMPLE = 2

function love.load()
 rect = {
  x = 5,
  y = 5,
  width = 10,
  height = 10,
  draw_x = 5,
  draw_y = 5,
  speed = 40
  }
end
function love.update(dt)
  if EXAMPLE == 1 then
    --
    rect.x = rect.x + rect.speed * dt
    rect.y = rect.y + rect.speed * dt
    --
    rect.x = math.floor(rect.x + 0.5)
    rect.y = math.floor(rect.y + 0.5)
    --
    rect.draw_x = rect.x
    rect.draw_y = rect.y
    --
  elseif EXAMPLE == 2 then
    --
    rect.x = rect.x + rect.speed * dt
    rect.y = rect.y + rect.speed * dt
    --
    rect.draw_x = math.floor(rect.x + 0.5)
    rect.draw_y = math.floor(rect.y + 0.5)
    --
  else
    love.event.quit()
  end
  
  print(delta)
  
end
function love.draw()
 push:start()
 love.graphics.rectangle("fill", rect.draw_x, rect.draw_y, rect.width, rect.height)
 push:finish()
end
User avatar
darkfrei
Party member
Posts: 1196
Joined: Sat Feb 08, 2020 11:09 pm

Re: Problems with slow movement speeds

Post by darkfrei »

placeholder wrote: Tue Mar 16, 2021 4:59 pm do you have any other suggestions, hopefully suggestions that you test by running the code before making the suggestion?
It must be much easier if you provide the .love file :)

Which "push" lib are you using? This one? https://github.com/Ulydev/push
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
placeholder
Prole
Posts: 13
Joined: Mon Mar 15, 2021 9:00 pm

Re: Problems with slow movement speeds

Post by placeholder »

yes, i am using that library. i have read that it is very commonly used, and i assumed that everyone here would have it already.

i'm sorry for not posting in the correct format, but i am just learning. i don't know how to export a file yet.

but the code is very short, and it takes only a second to copy paste into a new project folder with the push.lua file in it.
User avatar
darkfrei
Party member
Posts: 1196
Joined: Sat Feb 08, 2020 11:09 pm

Re: Problems with slow movement speeds

Post by darkfrei »

placeholder wrote: Tue Mar 16, 2021 7:25 pm yes, i am using that library. i have read that it is very commonly used, and i assumed that everyone here would have it already.

i'm sorry for not posting in the correct format, but i am just learning. i don't know how to export a file yet.

but the code is very short, and it takes only a second to copy paste into a new project folder with the push.lua file in it.
I've never heard about this lib, just googled it as "Love2d push", but wasn't sure if it's the right one.

Just zip your files (not folder!) And rename it into the *.love
Last edited by darkfrei on Tue Mar 16, 2021 8:06 pm, edited 1 time in total.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests