How to attached a small object to a larger object at a specific anchor point of the large object.

Hi, 

I have a physic object which will keep on swinging left right like a pendulum.

I want to attach a small physic object (as a physic sensor) at the tip of the pendulum.

No matter how I move or drag or swing the pendulum, the small physic object will stick at the tip as a sensor to sense collision with other object and trigger a function.

Here is my code:

local arrow = display.newImage(‘arrow.png’)

arrow.anchorX = 0.5

arrow.anchorY = 0.20

arrow.x = display.contentWidth / 2

arrow.y = 25

arrow.rotation = 0

arrow.status = “rotate”

physics.addBody(arrow, “static”)

arrow.collision = onCollision

slowDown = 0

local hotSpot = display.newCircle(100,100,5)

physics.addBody(hotSpot, “static”)

hotSpot:setFillColor(0,0,0)

hotSpot.anchorX = 0.5

hotSpot.anchorY = 0

physics.newJoint( “pivot”, arrow, hotSpot, 1, 1)

It doesn’t work. The hotSpot will only stick to the center of the arrow.

Hi @cshaopin,

You probably don’t need a physics joint for this. Instead, create the object as one multi-part body, with the hotSpot at the tip, as a sensor, and then when the object collides with something, you can detect which “index” of the body collided to ensure that it was the hotSpot, not the main arrow body.

This tutorial should help with the process:

http://coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/

Take care,

Brent Sorrentino

Hi @cshaopin,

You probably don’t need a physics joint for this. Instead, create the object as one multi-part body, with the hotSpot at the tip, as a sensor, and then when the object collides with something, you can detect which “index” of the body collided to ensure that it was the hotSpot, not the main arrow body.

This tutorial should help with the process:

http://coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/

Take care,

Brent Sorrentino