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?
Ship jitters
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Ship jitters
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.
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:
It could be shortened to this:
And you might not even need the do/end bit either. Anyway, hope some of that helps.
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
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
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
Last edited by BlackBulletIV on Sun Apr 24, 2011 8:06 am, edited 1 time in total.
Re: Ship jitters
As BlackBulletIV wrote, you have to make the camera movement dependent on the time to get a smooth movement. So instead of use this:
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).
Code: Select all
view:translate(vector((nx-lx)*2,(ny-ly)*2))
Code: Select all
view:translate( vector(nx-lx, ny-ly) * 0.5 * dt )
Who is online
Users browsing this forum: No registered users and 2 guests