Ship jitters

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
chris-kun
Prole
Posts: 17
Joined: Mon Feb 07, 2011 4:57 am
Location: SF Bay Area
Contact:

Ship jitters

Post by chris-kun »

current code here.

So basically the ship is just a bit jittery and I was wondering if there was a smoother way to do it. The only lines that matter are the three starting from 64. I was trying to compare the current point of the ship with where is was in the previous frame and move the camera according (I'm using the hump library.) Any ideas?
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Ship jitters

Post by BlackBulletIV »

I don't have the time to track down the jitters; although I have suspicion that it could be caused by your camera. I had trouble with the player jerking (or jittering, whatever) when using physics and a smooth moving camera. Taehl and bartbes helped me out there, so here's the code I came up with for my camera, it might help.

Code: Select all

camera.x = camera.x - (camera.x - (self.player.x - love.graphics.getWidth() / 2)) * dt * camera.speed
camera.y = camera.y - (camera.y - (self.player.y - love.graphics.getHeight() / 2)) * dt * camera.speed
Also, I noticed a block of code which most certainly doesn't need to be as big as it is. This is what I'm referring to:

Code: Select all

  do
    local px, py = playerBody:getWorldCenter()
    local pvec = vector.new(200, 200)
    local x, y = playerBody:getWorldCenter()
    local bvec = vector.new(x,y)
    local distance = pvec - bvec
    local f = 500000 / distance:len2()
    distance:normalize_inplace()
    local force = f * distance
    local fx = force.x
    local fy = force.y
    playerBody:applyForce(fx,fy)
  end
It could be shortened to this:

Code: Select all

do
  local distance = vector.new(200, 200) - vector.new(playerBody:getWorldCenter())
  local f = 500000 / distance:len2()
  distance:normalize_inplace()
  local force = f * distance
  playerBody:applyForce(force.x, force.y)
end
And you might not even need the do/end bit either. Anyway, hope some of that helps.
Last edited by BlackBulletIV on Sun Apr 24, 2011 8:06 am, edited 1 time in total.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Ship jitters

Post by vrld »

As BlackBulletIV wrote, you have to make the camera movement dependent on the time to get a smooth movement. So instead of

Code: Select all

view:translate(vector((nx-lx)*2,(ny-ly)*2))
use this:

Code: Select all

view:translate( vector(nx-lx, ny-ly) * 0.5 * dt )
What that does is move the camera depending with a speed depending how far away it is from the player body, so it will smoothly follow the player. The 0.5 can be changed to vary the speed of the camera movement (camera.speed in the other example).
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests