Getting distance moved this frame

Official forum for the Chipmunk2D Physics Library.

Getting distance moved this frame

Postby tekk » Mon Jun 15, 2015 8:00 pm

Is there any way to get the distance that a body's moved in the last frame? I'm trying to implement scrolling. Obviously I have my x and y offsets, and when the object being tracked reaches a certain part of the screen, I start to increase the offset by how quickly the body is moving in that direction. The trouble is that I can't figure out how to find it: both GetVelocity and GetForce come up extremely short.
tekk
 
Posts: 3
Joined: Wed Jun 10, 2015 8:22 pm

Re: Getting distance moved this frame

Postby AndyKorth » Tue Jun 16, 2015 2:27 pm

Try getting the position of the body and comparing it to the position of the body from the previous frame (which you saved in a variable). You can do this in your normal update loop.
User avatar
AndyKorth
Site Admin
 
Posts: 36
Joined: Wed Aug 15, 2007 3:56 pm

Re: Getting distance moved this frame

Postby tekk » Tue Jun 16, 2015 5:30 pm

Thanks, that was my first thought but I wasn't sure if there was a "proper" way to do it.
tekk
 
Posts: 3
Joined: Wed Jun 10, 2015 8:22 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest