1
\$\begingroup\$

Apologies if this is a reiteration, as I couldn't find another discussion of this over the past couple days.

Issue: I'm using libgdx and box2d, and I'm currently updating the sprite's position to the body's current position every render call. Using a debugRenderer to see the bodies, I see that there is fairly noticeable lag between the movement/position of the body and the sprite that is being moved relative to it.

Question: Is this lag normal, possibly to perform collisions ahead of time? If not, should I be manipulating/relating the positions differently?

Thanks in advance!

[Solution] This was a coding error on my part. Pointed out by a good reply below, I was updating the position of the sprite relative to the body and then stepping the physics. Thus never actually setting the sprite to the body's CURRENT position. Thanks!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ No the lead is not normal. Are you updating box2d first and then sprites position afterwards? \$\endgroup\$ Commented Feb 22, 2012 at 23:46
  • \$\begingroup\$ Are you updating your physics world in your render loop? You might need to implement a fixed timestep for the physics update as well. It's difficult to tell what's wrong without posting code. \$\endgroup\$
    – Chuck D
    Commented Feb 23, 2012 at 7:52
  • \$\begingroup\$ Thanks for the quick replies, will look into both of these when I get the chance and post back as to if either was the problem. I think it might be ClassicThunder's post that is on the right track. I think I inadvertently set sprite position to body, then stepped the physics! Thus never having them in the same spot... \$\endgroup\$
    – While-E
    Commented Feb 23, 2012 at 17:04

1 Answer 1

2
\$\begingroup\$

[Solution] This was a coding error on my part. Pointed out by a good reply above, I was updating the position of the sprite relative to the body and then stepping the physics. Thus never actually setting the sprite to the body's CURRENT position. Thanks!

\$\endgroup\$
1
  • 3
    \$\begingroup\$ If this fix worked for you, please accept your own answer to show that it was resolved. \$\endgroup\$
    – user14497
    Commented Mar 25, 2012 at 1:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .