Anchor and Physics Body Shapes

Hi,

I’m using Level Director (Graphics 2.0 Enabled) to create polygon shape physics body on my object.

It works fine except when I set the AnchorX-Y to 0.5 aka center.

When the center anchor is set the physics body runs from the center point.

Is there a setting in Level Director to have the physics body calculated relative to the Anchor?

I need to use the center point for rotating the enemies to face the player.

Thanks for any input or workarounds.

Hi @jm.8.sc2,

I can’t speak for Level Director, but physics bodies should work as expected around a center point, where the coordinates of the polygon are relative to 0,0 which is the display object’s center point.

Can you post a screenshot which shows the object you’re trying to build a body for? And could you turn on “hybrid” draw mode so it shows the actual physics body which is being drawn?

http://docs.coronalabs.com/api/library/physics/setDrawMode.html

Screenshots can be posted by clicking the “More Reply Options” button below the response submission box, and then on the next page you can upload image(s).

Best regards,

Brent

Hi,

Thanks for the quick reply, Screenshot is attached.

This is the code Level Director is generating if it helps any

 assets['evilguy\_1\_png']={ file = 'evilguy\_1.png', name = 'evilguy\_1\_png', class = 'enemy', anchorX = 0.5, anchorY = 0.5, width = 150, height = 150, frame = 0, spriteSheetName = '', frameCount = 0, health = '50', sequenceData = {}, sequenceInfo = {default = '', play= false }, physics = { isEnabled = true, source = 'Asset', bodyType = 'dynamic', isFixedRotation = false, isSleepingAllowed = true, isSensor = true, isBullet = false, shapes = { {bodyShape = 'Rectangle', shape = {-63,-44,57,-43,60,38}, bounce = 0, friction = 0, density = 1, radius = 10, categoryBits = 2, maskBits = 9, groupIndex = 0}, } } }

 objProps = { name = 'img\_164', objType = 'LDObjectImage', class = 'enemy', width = 144, height = 144, x = 776, y = 312, xScale = 0.96 \* 1, yScale = 0.96 \* 1, rotation = 0, enableDrag = false, anchorX = 0.5, anchorY = 0.5, alpha = 1, isVisible = true, blendMode = 'normal', assetName = 'evilguy\_1\_png', }

Hi @jm.8.sc2,

It doesn’t appear that it’s accepting your physics shape definition at all. It’s a square in the screenshot, but your shape definition indicates a triangle. I’m not sure why that would be…

Brent

Hi, the body shape i’m using is the Level Director default “rectangle”.

Even when I use the custom shape editor it still does not run relative to the center. But starts at the center potition.

Thanks.

Hi @jm.8.sc2,

I’m not sure how much more support I can provide, since Level Director is a 3rd-party product. Since Graphics 2.0, objects work around a center point, so you’re not really “changing” the object by setting its anchor at 0.5,0.5. Working with physics bodies around center points is the normal, default behavior, and I don’t know why Level Director would be treating this any differently. If you were trying to set a non-center anchor point, then there might be some issues to work out, but around a center point, nothing should be unusual.

Brent

Hi,

Thanks for your support. I figured it out there is an option in Level Director to set “global” Anchor values.

Attached screenshot in-case anyone else is looking for same solution.

You can close this thread.  :slight_smile:

Hi, Sorry for the delay but it looks like you figured it out, is everything working as expected now?

Also, thanks Brent for helping out.

JFYI - looking at your example it appears that you originally defined a ‘polygon’ shape but then afterwards changed the body shape back to rectangle, but LD doesn’t clear the points hence why you still the polygon shape when exported.

Simply switching the body shape back to polygon will use these points if needed.

Hi @jm.8.sc2,

I can’t speak for Level Director, but physics bodies should work as expected around a center point, where the coordinates of the polygon are relative to 0,0 which is the display object’s center point.

Can you post a screenshot which shows the object you’re trying to build a body for? And could you turn on “hybrid” draw mode so it shows the actual physics body which is being drawn?

http://docs.coronalabs.com/api/library/physics/setDrawMode.html

Screenshots can be posted by clicking the “More Reply Options” button below the response submission box, and then on the next page you can upload image(s).

Best regards,

Brent

Hi,

Thanks for the quick reply, Screenshot is attached.

This is the code Level Director is generating if it helps any

 assets['evilguy\_1\_png']={ file = 'evilguy\_1.png', name = 'evilguy\_1\_png', class = 'enemy', anchorX = 0.5, anchorY = 0.5, width = 150, height = 150, frame = 0, spriteSheetName = '', frameCount = 0, health = '50', sequenceData = {}, sequenceInfo = {default = '', play= false }, physics = { isEnabled = true, source = 'Asset', bodyType = 'dynamic', isFixedRotation = false, isSleepingAllowed = true, isSensor = true, isBullet = false, shapes = { {bodyShape = 'Rectangle', shape = {-63,-44,57,-43,60,38}, bounce = 0, friction = 0, density = 1, radius = 10, categoryBits = 2, maskBits = 9, groupIndex = 0}, } } }

 objProps = { name = 'img\_164', objType = 'LDObjectImage', class = 'enemy', width = 144, height = 144, x = 776, y = 312, xScale = 0.96 \* 1, yScale = 0.96 \* 1, rotation = 0, enableDrag = false, anchorX = 0.5, anchorY = 0.5, alpha = 1, isVisible = true, blendMode = 'normal', assetName = 'evilguy\_1\_png', }

Hi @jm.8.sc2,

It doesn’t appear that it’s accepting your physics shape definition at all. It’s a square in the screenshot, but your shape definition indicates a triangle. I’m not sure why that would be…

Brent

Hi, the body shape i’m using is the Level Director default “rectangle”.

Even when I use the custom shape editor it still does not run relative to the center. But starts at the center potition.

Thanks.

Hi @jm.8.sc2,

I’m not sure how much more support I can provide, since Level Director is a 3rd-party product. Since Graphics 2.0, objects work around a center point, so you’re not really “changing” the object by setting its anchor at 0.5,0.5. Working with physics bodies around center points is the normal, default behavior, and I don’t know why Level Director would be treating this any differently. If you were trying to set a non-center anchor point, then there might be some issues to work out, but around a center point, nothing should be unusual.

Brent

Hi,

Thanks for your support. I figured it out there is an option in Level Director to set “global” Anchor values.

Attached screenshot in-case anyone else is looking for same solution.

You can close this thread.  :slight_smile:

Hi, Sorry for the delay but it looks like you figured it out, is everything working as expected now?

Also, thanks Brent for helping out.

JFYI - looking at your example it appears that you originally defined a ‘polygon’ shape but then afterwards changed the body shape back to rectangle, but LD doesn’t clear the points hence why you still the polygon shape when exported.

Simply switching the body shape back to polygon will use these points if needed.