I've just started with Box2D and have come across a strange problem.
I have a simple function to constrain object position to within a predefined area.
I do this by getting the body's world position, checking this against the predefined area's bounding box values, and applying a force to the body to keep it within.
if (bodyWorldPos.x >= worldWidth)
body.setLinearVelocity(...);
This works fine.
However, if the body collides with another body, this simple method stops working. The body's world position, retrieved like this:
body.getWorldPoint(body.getPosition())
returns wrong values.
Is this a bug in Box2D for LibGDX or am I doing something wrong?
The function getWorldPoint converts a point from 'local coordinates' (relative to the body's 0,0 position) to global coordinates (relative to 0,0 in the world).
I think for this purpose you can just use getPosition() only.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.