Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question
1  
No the lead is not normal. Are you updating box2d first and then sprites position afterwards? –  ClassicThunder Feb 22 '12 at 23:46
    
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. –  Rubber Mallet Feb 23 '12 at 7:52
    
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... –  While-E Feb 23 '12 at 17:04

1 Answer 1

up vote 2 down vote accepted

[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!

share|improve this answer
3  
If this fix worked for you, please accept your own answer to show that it was resolved. –  K.G. Mar 25 '12 at 1:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.