Incline an object to certain angle.

Hi All,

I stucked here badly.

I have two objects associated with physics, where I detect the collision among them. When I rotate one of the object, then the collision detection behaves abnormally. The collision detects even in blank spaces where there is no contact with objects. I have rotate the object with -30

Please suggest…

The physics engine will see the object before any changes to rotation on the object, so it will pick up the original shape.  Set the line of code below and you will see what I mean.

physics.setDrawMode( “hybrid” )

I don’t think that’s correct.

In my game I rotate physic objects all the time and there’s no problem with it. And the Drawmode proofs me right.

The questions how you rotate the object?

Do you

  1. only set the the new rotation?

object.rotation = -30

  1. use a transition to rotate it?

transition.to(object,{rotation=object.rotation-30})

  1. use a physic way to do so and check with a runtime listener?

object:setAngularvelocity(-10)

I only encountered problems with method 2 by now.

Greetings Torben

…or if the “object” in question being rotated is a group , containing the actual individual physics objects which are NOT individually rotated, then won’t work == big problems.

as per prior suggestion, set hybrid draw mode so you can see it as physics sees it:  if your display objects are rotated, but the physics outlines are NOT rotated, then that’s the reason.

Hi @rajumahato,

Are you rotating the object(s) around a non-center reference point, i.e. the top-left corner? Collisions work around the central reference point of the object.

Brent

Thanks all for your reply.

But still its not working.

Here is my code block for one of the object.

local testhurdle = display.newImageRect( verticalBarImgPath, hurdleWidth, displayHeight * 0.55 )

testhurdle:setReferencePoint( display.TopLeftReferencePoint )

physics.addBody( testhurdle, “static” )

testhurdle.x = displayWidth * 0.25

testhurdle.y = displayHeight * 0.15

testhurdle.type = hurdleType

testhurdle:rotate ( -30 )

levelViewGroup:insert( testhurdle )

You’re still rotating and positioning the object around a corner point (top left). The object will appear properly on the screen, but physics collisions will not work properly. You need to determine where the center point of the object is, for the real position you need, and place it there (and omit line 2 in the code you posted).

Best regards,

Brent

The physics engine will see the object before any changes to rotation on the object, so it will pick up the original shape.  Set the line of code below and you will see what I mean.

physics.setDrawMode( “hybrid” )

I don’t think that’s correct.

In my game I rotate physic objects all the time and there’s no problem with it. And the Drawmode proofs me right.

The questions how you rotate the object?

Do you

  1. only set the the new rotation?

object.rotation = -30

  1. use a transition to rotate it?

transition.to(object,{rotation=object.rotation-30})

  1. use a physic way to do so and check with a runtime listener?

object:setAngularvelocity(-10)

I only encountered problems with method 2 by now.

Greetings Torben

…or if the “object” in question being rotated is a group , containing the actual individual physics objects which are NOT individually rotated, then won’t work == big problems.

as per prior suggestion, set hybrid draw mode so you can see it as physics sees it:  if your display objects are rotated, but the physics outlines are NOT rotated, then that’s the reason.

Hi @rajumahato,

Are you rotating the object(s) around a non-center reference point, i.e. the top-left corner? Collisions work around the central reference point of the object.

Brent

Thanks all for your reply.

But still its not working.

Here is my code block for one of the object.

local testhurdle = display.newImageRect( verticalBarImgPath, hurdleWidth, displayHeight * 0.55 )

testhurdle:setReferencePoint( display.TopLeftReferencePoint )

physics.addBody( testhurdle, “static” )

testhurdle.x = displayWidth * 0.25

testhurdle.y = displayHeight * 0.15

testhurdle.type = hurdleType

testhurdle:rotate ( -30 )

levelViewGroup:insert( testhurdle )

You’re still rotating and positioning the object around a corner point (top left). The object will appear properly on the screen, but physics collisions will not work properly. You need to determine where the center point of the object is, for the real position you need, and place it there (and omit line 2 in the code you posted).

Best regards,

Brent