Need help with preserving the Collision boundaries of an object when changing the object reference point

Hi all,

I read an old post that mention the following:

“When you turn a display object into a physics object, the Physics engine owns the object and
has its own rules about the object. Physics assumes the reference point of the object is the center of the object so object:setReferencePoint() may change the reference point from Corona’s Display Object point of view but not for the Physics engine. This affects collisions and how other physics
bodies interact…”

So how can I change the reference point of a triangle (I want it to rotate around it base) and preserve it collision boundaries?

How can I modify the Physics engine to follow the new reference point?

 

Regards,

Guy

 

 

 

Hi Guy,

For this, I would suggest one of two methods:

  1. you can build the triangle image on a larger “canvas” with transparent pixels all around. In this, you’d position the rotation point (center of the triangle base?) at the very center of the overall canvas. That way, when you rotate the object in Corona, it would revolve around that center point. Then, in regards to the physics body, you’ll need to build the triangle boundary offset from the center… but you’d need to build a custom shape for any triangle, so it’s really no extra amount of work.

  2. you can use a Runtime “enterFrame” function to rotate the triangle using math calculations. For example, you’d update its rotation angle and position based on the desired position, with the rotation point at its base factored into the equation. Ultimately, this is a fair amount more work than option #1, but you may consider it.

Hope this helps,

Brent

Thank you Brent,

I like the first method you suggested, indeed, no extra amount of work.

I creates a new object,  transparent circle with the triangle inside

Now I need to figure out why when it display on the screen I see a big triangle that behave as before (seems that circle has been remove).

 

The method you suggested work fine when the circle is not transparent

 

Regards,

Guy

 

Ok,

I found my problem.

When I saved the image as a png file with transparent circle,the paint tool remove the circle.

When I save the image with white circle it works, corona remove the white background in display.

Thanks again Brent

regards,

Guy

 

Hi Guy,

For this, I would suggest one of two methods:

  1. you can build the triangle image on a larger “canvas” with transparent pixels all around. In this, you’d position the rotation point (center of the triangle base?) at the very center of the overall canvas. That way, when you rotate the object in Corona, it would revolve around that center point. Then, in regards to the physics body, you’ll need to build the triangle boundary offset from the center… but you’d need to build a custom shape for any triangle, so it’s really no extra amount of work.

  2. you can use a Runtime “enterFrame” function to rotate the triangle using math calculations. For example, you’d update its rotation angle and position based on the desired position, with the rotation point at its base factored into the equation. Ultimately, this is a fair amount more work than option #1, but you may consider it.

Hope this helps,

Brent

Thank you Brent,

I like the first method you suggested, indeed, no extra amount of work.

I creates a new object,  transparent circle with the triangle inside

Now I need to figure out why when it display on the screen I see a big triangle that behave as before (seems that circle has been remove).

 

The method you suggested work fine when the circle is not transparent

 

Regards,

Guy

 

Ok,

I found my problem.

When I saved the image as a png file with transparent circle,the paint tool remove the circle.

When I save the image with white circle it works, corona remove the white background in display.

Thanks again Brent

regards,

Guy