physics vector to move 1px per update?

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
sillydino
Prole
Posts: 4
Joined: Thu Aug 20, 2009 9:22 pm

physics vector to move 1px per update?

Post by sillydino »

Hello all,

I'm trying to right my vector so that it moves my body at 1 pixel per update cycle. If I set my vector to 1, nothing happens, if I set my vector to 50, the body moves, but skips pixels. I've read the box2d documentation and the love documentation but I can't figure out a way to compute this. Can someone please help?

Thanks!
User avatar
napco
Party member
Posts: 129
Joined: Fri Jun 12, 2009 9:28 pm
Location: Ital... ehm...

Re: physics vector to move 1px per update?

Post by napco »

Hi! I'm not very good with physics, but i think that the value you've changed from 1 to 50 is the intensity of the movement (you can push a glass with a finger either slowly and quickly). Physics module takes advance of the dt (delta time) value, so it's difficult (but not impossible, i think) to move your body by 1 pixel per update. I'll give a look and then i'll reply if i find the solution. Another solution is to build your own physics module (in fact to move a sprite in my game i don't use physics).
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: physics vector to move 1px per update?

Post by TechnoCat »

If you want to move it one pixel per update you could write this in update(dt)

Code: Select all

body:setX(body:getX()+1)
This moves 1 pixel/update

But you are more likely wanting to do it one pixel per second. This is because the update cycle frequency highly depends on the speed of the computer it is being run on.
You would do this in update(dt)

Code: Select all

body:setX(body:getX()+1*dt)
This moves 1 pixel/second
sillydino
Prole
Posts: 4
Joined: Thu Aug 20, 2009 9:22 pm

Re: physics vector to move 1px per update?

Post by sillydino »

TechnoCat wrote:If you want to move it one pixel per update you could write this in update(dt)

Code: Select all

body:setX(body:getX()+1)
This moves 1 pixel/update

But you are more likely wanting to do it one pixel per second. This is because the update cycle frequency highly depends on the speed of the computer it is being run on.
You would do this in update(dt)

Code: Select all

body:setX(body:getX()+1*dt)
This moves 1 pixel/second
I tried moving via the setX/Y functions on Body, but the collision detection doesn't work. Does anyone know how to get both pixel by pixel movement with collision detection?
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: physics vector to move 1px per update?

Post by TechnoCat »

Every update also check if it is colliding, if it is colliding move it back before update(dt) is finished.
sillydino
Prole
Posts: 4
Joined: Thu Aug 20, 2009 9:22 pm

Re: physics vector to move 1px per update?

Post by sillydino »

TechnoCat wrote:Every update also check if it is colliding, if it is colliding move it back before update(dt) is finished.
That is what I was doing before integrating with the physics module. My goal in using the physics module is to inherit the collision detection. At the same time, I need to be able to track at a pixel level so when the unit hits the center of the screen I can transition motion back to the map scroller(for mimicking a camera). I gotta believe there's a way to back compute from 'one pixel per update' to 'some vector', I'm just too dumb to figure it out.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests