Wrong physics collisions when Body is Rotated and Reference Point is NOT Centered

This is probably the only issue I’m having before releasing the SVG Level Builder.

If I have a physics body rotated and its reference point is not the center, collisions won’t work as expected. They will either process as the body was in front or behind of the actual body.

Another one: the ground rectangle is TopLeft Reference Point too, but since it is not rotated the circles are correctly colliding.

On the following test code, the circles collide before hitting the first rectangle and then collide in the middle of the second rectangle.

[lua]local physics = require(“physics”)
physics.start()
physics.setDrawMode(“debug”)

for i=1,10 do
local circle = display.newCircle(100, 100, 10)
circle.x = 250
circle.y = 180
physics.addBody(circle, “dynamic”, {radius = 10})
end

local rect = display.newRect(0, 0, 100, 20)
rect:setReferencePoint(display.TopLeftReferencePoint)
rect.x = 200; rect.y = 200
rect.rotation = 10
physics.addBody(rect, “static”)

local rect = display.newRect(0, 0, 100, 20)
rect:setReferencePoint(display.TopLeftReferencePoint)
rect.x = 300; rect.y = 200
rect.rotation = -10
physics.addBody(rect, “static”)[/lua]

[import]uid: 10990 topic_id: 8019 reply_id: 308019[/import]

Noticed the thing on the screenshots: Debug boxes are drawn correctly, and the collisions are processed as the box were positioned as centered [import]uid: 10990 topic_id: 8019 reply_id: 28551[/import]

Looks like I’m not alone: http://developer.anscamobile.com/forum/2010/10/26/pinball-physics [import]uid: 10990 topic_id: 8019 reply_id: 28553[/import]

@karnakgames : did you enter this as a bug report?

please do and enter this forum also as a link to refer to

c. [import]uid: 24 topic_id: 8019 reply_id: 28672[/import]

@carlos: yes, I opened the bug on the same day as the topic.
This is really the only issue I’m having before releasing the SVG Builder.

Case: 4272

Thanks. [import]uid: 10990 topic_id: 8019 reply_id: 28768[/import]

Thanks, will flag as fix asap - but just know we are knee deep in android … and some juggling will have to happen …

c [import]uid: 24 topic_id: 8019 reply_id: 28770[/import]

Thanks again Carlos.

I just made another test and noticed that rectangles and custom shaped bodies go crazy with TopLeft reference point, not only when rotated, but always. [import]uid: 10990 topic_id: 8019 reply_id: 28804[/import]

Ah ok. since am not the one who wrote the physics code… and Eric is out sick… it will take another two days before he can look at this…

Am knee deep in Android and I didn’t write the phsyics code …

Earliest, Friday for an answer.

C [import]uid: 24 topic_id: 8019 reply_id: 29042[/import]

Bump! Any update on the situation @Carlos? I need a fix for this problem, but it still seems to exist as of the newest stable release! Thank you for you continued support Ansca! [import]uid: 67379 topic_id: 8019 reply_id: 42807[/import]

What you are seeing is the limitation of Box2D used to implement Physics in Corona.

When you turn a vector into a physics object, the Physics engine owns the object and has it own rules about the object. Physics assumes the reference point of the object is the center of the object so setReferencePoint() may change the reference point from Corona’s Display Object point of view but not from the Physics engine.

The same goes for scaling and rotating the object. You can scale the object up or down and rotate it but the Physics engine still sees the object as it was before the changes.

You can see how the Physics engine view the object with Debug view.

This issue is well known to Box2D users and we need to update our Physic API docs to make this clearer. [import]uid: 7559 topic_id: 8019 reply_id: 42901[/import]

Thank you for the response, so is there any workaround for this issue? I really need to rotate a kinematic sensor around a leftcenter reference point, but I also need it to register collisions normally. [import]uid: 67379 topic_id: 8019 reply_id: 43335[/import]