Body speeding off ignoring scrolling ground


This Content is from Stack Overflow. Question asked by Connor Club

I am currently trying to make a 2D car game with pybox2D
I have gotten to the stage where the ground needs to scroll with the car so it stays on screen.
I have this bit of code doing this currently:

ground.body.worldCenter[0] = SW/PPM - car.chassis.worldCenter[0] - (SW//2)/PPM

(SW/PPM - and - (SW//2)/PPM are just used to keep it in the middle of the screen and make sure it moves opposite of the car)
ground and car are instances of special classes I made to connect all parts of the bodies (different sections of ground for concave shapes, wheels, chassis, etc) into objects.
The problem is that the car just speeds off screen still, even though worldCenter should always keep track of the object so the car should always be in the center of the screen.
My car movement system is a simple joint motor system.

Does anyone know why this is happening?
More importantly, is this code efficient or is there a better way of tracking a body?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?