Collision related question

Hey guys, Im having a problem thats probably very simple to solve.

So I have a large cloud PNG image that I have placed on the bottom of the device’s screen, its a hill like shape with regular bumps going up and down that allows space for player to float into. The problem is that the player and the base cloud dont interact but rather pass through each other instead. What I want to happen is to allow the player image and cloud image to collide so that whenever the player hits the base cloud it = game over. 

cheers 

heres my setup so far: 

–player bird–

local bird = display.newImageRect("images/player1.png", 49, 39) bird.x, bird.y = 100, 140 bird.name = "bird" physics.addBody( bird, "dynamic", { friction=0.5, bounce=0 } ) group:insert(bird)

– Cloud–

local cloud1 = display.newImage("images/clouds1.png") cloud1:setReferencePoint(display.BottomLeftReferencePoint) cloud1.x = 0 cloud1.y = 325 cloud1.name = "bottom" physics.addBody( cloud1, "static", {isSensor = true } ) group:insert(cloud1) 

– Collision – 

function onCollision( event ) if(event.object1.name == "bird" and event.object2.name == "bottom") then print("bottom") end end

Hi @dip,

The bird and the cloud are probably colliding, but not “physically” since you’ve set the cloud to be a sensor object (isSensor=true). Remove that, and they should collide as you expect. However, this won’t necessarily make sense from a design standpoint, since a cloud is not a “solid object” like a rock. In other words, I suggest that you keep the cloud as a sensor, and just do something in the collision handler. If that collision handler is not working, then you’ve set it up incorrectly somehow with your conditional logic, or you forgot to add the correct collision listener, or something like that.

Best regards,

Brent

Hi Brent
Thanks for the reply. I only used the clouds as placeholders but I’ll keep that in mind when I come to the finished piece. As for the collision, The bird and cloud still don’t collide after removing the sensor from the cloud. I had the collision set to to print a line but that never shows.

They still float straight through without any form of collision being detected.

Hi @dip,

Did you turn on “hybrid” draw mode to see what the physics bodies are doing? I also suggest that you position the cloud without the reference point thing, and position it by its center point instead… that may be throwing off how Box2D considers the placement of its body.

Brent

Hi Brent, 

Thanks for the help, removing the referencePoint and manually adjusting the coordinates seemed to do the trick. However I have another issue with the cloud.png images. As I float up, there seems to be an invisible straight line that blocks the indents of the cloud. What should happen is that the edges of the cloud image should be the collision itself. Did I do something wrong with the image created in photoshop?

here is the image and what I mean: 

(the red line shows the invisible collision

Can you show us a screen shot in hybrid draw mode?   I’m guessing the physics body is just a box around the cloud.

Use the Physics Editor to create custom physics shapes for Corona.    

http://www.codeandweb.com/physicseditor

Here is the Hybrid screenshot. Your right, the physics is like a box. So in Photoshop, this type of shape has problems or is it done wrong? I will attempt to use the physics editor you linked.

You’re telling Corona to assign a physics body to a square image, so you get a square body.   You could come up with a list of vertices manually to define the shape of the cloud, but that would be painstaking.   

The Physics Editor is the way to go.   

Thanks for the help, ill definitely take a look at the Physics Editor. 

cheers.

Hi guys,

We’re finishing up testing on an image auto-trace feature for physics bodies, and once tested, it will be released into a daily build. However, @dip, this will not be available to you (as a Starter) until the next public release, so you may still want to explore Physics Editor for your immediate needs.

Best regards,

Brent

Very cool.   Will it work with sprite sheets?

That sounds great, can’t wait to try it out.

Also, thanks for the help guys. Very much appreciated 

Hi @davemikesell,

At this initial launch, it won’t work with image sheets (for example, a whole sheet of character sprite animations). It’s intended to make tracing of basic physics objects easier, not auto-trace full sprite sheets.

Brent

Hi @dip,

The bird and the cloud are probably colliding, but not “physically” since you’ve set the cloud to be a sensor object (isSensor=true). Remove that, and they should collide as you expect. However, this won’t necessarily make sense from a design standpoint, since a cloud is not a “solid object” like a rock. In other words, I suggest that you keep the cloud as a sensor, and just do something in the collision handler. If that collision handler is not working, then you’ve set it up incorrectly somehow with your conditional logic, or you forgot to add the correct collision listener, or something like that.

Best regards,

Brent

Hi Brent
Thanks for the reply. I only used the clouds as placeholders but I’ll keep that in mind when I come to the finished piece. As for the collision, The bird and cloud still don’t collide after removing the sensor from the cloud. I had the collision set to to print a line but that never shows.

They still float straight through without any form of collision being detected.

Hi @dip,

Did you turn on “hybrid” draw mode to see what the physics bodies are doing? I also suggest that you position the cloud without the reference point thing, and position it by its center point instead… that may be throwing off how Box2D considers the placement of its body.

Brent

Hi Brent, 

Thanks for the help, removing the referencePoint and manually adjusting the coordinates seemed to do the trick. However I have another issue with the cloud.png images. As I float up, there seems to be an invisible straight line that blocks the indents of the cloud. What should happen is that the edges of the cloud image should be the collision itself. Did I do something wrong with the image created in photoshop?

here is the image and what I mean: 

(the red line shows the invisible collision

Can you show us a screen shot in hybrid draw mode?   I’m guessing the physics body is just a box around the cloud.

Use the Physics Editor to create custom physics shapes for Corona.    

http://www.codeandweb.com/physicseditor

Here is the Hybrid screenshot. Your right, the physics is like a box. So in Photoshop, this type of shape has problems or is it done wrong? I will attempt to use the physics editor you linked.

You’re telling Corona to assign a physics body to a square image, so you get a square body.   You could come up with a list of vertices manually to define the shape of the cloud, but that would be painstaking.   

The Physics Editor is the way to go.