Hi!
I check the movement of the image by pressing the second button of the mouse.
I do not understand why the image moves with jerks.
How to make the movement more smooth?
aangle = math.atan2(self.destY  self.y, self.destX  self.x)
dist = math.sqrt((self.destX  self.x)^2 + (self.destY  self.y)^2)
self.x = self.x + math.cos(aangle)*self.speed*dt
self.y = self.y + math.sin(aangle)*self.speed*dt
Thanks for your help!
Jerking in move
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Jerking in move
 Attachments

 Space.love
 (222.82 KiB) Downloaded 49 times

 Party member
 Posts: 164
 Joined: Wed Oct 05, 2016 11:53 am
Re: Jerking in move
A couple of things are at play here.
First, in your love.update you have the following:
Here you are updating the camera before player moves. What this effectively does is that the camera is "lagging" behind one frame's worth of movement, which contributes to the jerky camera. Just flip the lines around, and this is fixed:
Second thing is that you are moving the player about in fractional units, ie. nonintegers. This affects rendering a little bit, since you're also moving the camera about in noninteger steps. There's different ways on how to deal with this, but for example you could only move the camera in integers, and draw the player graphic at integer positions. Effectively, round to nearest integer.
These changes made the movement and camera smooth on my end.
First, in your love.update you have the following:
Code: Select all
function love.update(dt)
 ...
local dx,dy = Player.x  camera.x, Player.y  camera.y
camera:move(dx/2, dy/2)
Player:update(dt)
end
Code: Select all
function love.update(dt)
 ...
Player:update(dt)
local dx,dy = Player.x  camera.x, Player.y  camera.y
camera:move(dx/2, dy/2)
end
Code: Select all
 Returns 'n' rounded to the nearest 'deci'th (defaulting whole numbers).
 This function is taken from https://love2d.org/wiki/General_math, you could put it at the top of main.lua or someplace else
function math.round(n, deci) deci = 10^(deci or 0) return math.floor(n*deci+.5)/deci end
 in main.lua
function love.update(dt)
 ...
Player:update(dt)
local dx,dy = Player.x  camera.x, Player.y  camera.y
camera:move(math.round(dx), math.round(dy))
end
 in player.lua
function Player:draw()
local x,y = math.round(self.x), math.round(self.y)
love.graphics.draw(self.img, x, y, round(self.angle,0), self.sx, self.sy, self.ox, self.oy)
end
Re: Jerking in move
Thanks for the answer!
Big jerks disappeared. Indeed, your code is very helpful:
But here the movement of the image was not smooth.
Add more image to become visible little jerks.
How to achieve a smooth movement?
When rounding the coordinates of a small image, the motion becomes a little smoother, but it does not go in a straight line.
What other methods are there for this?
I put the new code space.love
Thanks for your help!
Big jerks disappeared. Indeed, your code is very helpful:
Code: Select all
Player:update(dt)
...
camera:move(math.round(dx), math.round(dy))
Add more image to become visible little jerks.
How to achieve a smooth movement?
When rounding the coordinates of a small image, the motion becomes a little smoother, but it does not go in a straight line.
What other methods are there for this?
I put the new code space.love
Thanks for your help!
 Attachments

 Space.love
 (223.54 KiB) Downloaded 52 times
Who is online
Users browsing this forum: No registered users and 16 guests