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!
physics vector to move 1px per update?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: physics vector to move 1px per update?
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).
- 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?
If you want to move it one pixel per update you could write this in update(dt)
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)This moves 1 pixel/second
Code: Select all
body:setX(body:getX()+1)
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)
Re: physics vector to move 1px per update?
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?TechnoCat wrote:If you want to move it one pixel per update you could write this in update(dt)This moves 1 pixel/updateCode: Select all
body:setX(body:getX()+1)
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)This moves 1 pixel/secondCode: Select all
body:setX(body:getX()+1*dt)
- 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?
Every update also check if it is colliding, if it is colliding move it back before update(dt) is finished.
Re: physics vector to move 1px per update?
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.TechnoCat wrote:Every update also check if it is colliding, if it is colliding move it back before update(dt) is finished.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests