How do you mirror a physics body?

I have a bird flying left to right. After a collision it may be flying right to left and need to mirror body so the bird appears to fly beak forward. I tried scale(-1,1) but this didn’t work on the physics body.

Thoughts?

Dave [import]uid: 18679 topic_id: 24878 reply_id: 324878[/import]

Is your physics body complex? or merely a normal square/rectangle type or a radius type?
I would give it a radius and merely create commands to flip the image when you want it to flip.

[import]uid: 58922 topic_id: 24878 reply_id: 100929[/import]

It is a normal square/rectangle. Can you expand on the suggestion to give it a radius and flip the image. I have only done business apps and this is my first time working with physics. [import]uid: 18679 topic_id: 24878 reply_id: 100983[/import]

well here is an example of what you could do:

[lua]local movieclip = require( “movieclip” )

local player = movieclip.newAnim{ “birdfacingright.png”, “birdfacingleft.png” }
player.x = 55
player.y = 250
physics.addBody(player, “dynamic”, {radius = 10})

local function onCollision (event)
if event.phase == “began” then
player:stopAtFrame(2)
end
end
player:addEventListener(“collision”, onCollision)[/lua]

basically you could have 2 images using movie clip and dictate that it stops on a set frame on collision. there are any number of ways you can do this, it just depends on what you want to use as the bird. movie clip like above? sprite? etc. Now if you’d rather mirror it simply do this:
[lua]local player = display.newImage( “bird.png” )
player.x = 55
player.y = 250
physics.addBody(player, “dynamic”, {radius = 10})

local function onCollision (event)
if event.phase == “began” then
player.xScale = player.xScale * -1
end
end
player:addEventListener(“collision”, onCollision)[/lua]

Just a couple ways you can do it. Hope this helps :slight_smile:
-Winter [import]uid: 58922 topic_id: 24878 reply_id: 101230[/import]

Thanks Winter! [import]uid: 18679 topic_id: 24878 reply_id: 101309[/import]