Show fall simulating

I have created Show fall using following code but after  snowfall, it  is not collecting properly at the ground(at the bottom of the screen)

local function spawnSnowFlake()

        local flake = display.newCircle(0,0,2)

        flake.x = math.random(display.contentWidth)

        flake.y = -2

        local wind = math.random(80) - 40

        physics.addBody( flake, { density=-4, friction=0, bounce=0} )

end

ground a plain border-

    physics.addBody( border, “static”, { friction=0.5, bounce=0 } )

I see the circles are aligned in a sequence, instead of clubbed like show. attached the screen shot.

Any suggestions??

Sudheer 

Hi Sudheer,

By default, when you add a physics body, it will trace a square/rectangle around the object. If you want a circular physics body, for these snowflakes, you need to add the “radius” property to the physics body add:

[lua]

physics.addBody( flake, { radius=2, density=-4, friction=0, bounce=0} )

[/lua]

This will make them behave as you see them on screen, not stack like “cubes” as they are currently doing.

Remember, you can always check what the physics engine is doing, visually, by changing the draw mode:

[lua]

physics.setDrawMode( “hybrid” )

[/lua]

Sincerely,

Brent Sorrentino

Thanks Brent Sorrentino,

 

One last question, can we add magnetic nature or gravity between two flakes?

Because some flakes are moving/rotating after hitting ground flakes and snow forming is linearly and not appears like heap. 

 

Sudheer

One suggestion I have is to make the physical body of the flakes smaller than the images, so that when they land on top of each other they appear to merge into the pile of snow. You could experiment with changing the flakes to static objects once they land so they don’t roll.

You might also want to increase the friction on the flakes, so they “cling” to each other a bit more. This may (or may not) have the effect that you want, but it’s worth a try. :slight_smile:

Brent

Hi Sudheer,

By default, when you add a physics body, it will trace a square/rectangle around the object. If you want a circular physics body, for these snowflakes, you need to add the “radius” property to the physics body add:

[lua]

physics.addBody( flake, { radius=2, density=-4, friction=0, bounce=0} )

[/lua]

This will make them behave as you see them on screen, not stack like “cubes” as they are currently doing.

Remember, you can always check what the physics engine is doing, visually, by changing the draw mode:

[lua]

physics.setDrawMode( “hybrid” )

[/lua]

Sincerely,

Brent Sorrentino

Thanks Brent Sorrentino,

 

One last question, can we add magnetic nature or gravity between two flakes?

Because some flakes are moving/rotating after hitting ground flakes and snow forming is linearly and not appears like heap. 

 

Sudheer

One suggestion I have is to make the physical body of the flakes smaller than the images, so that when they land on top of each other they appear to merge into the pile of snow. You could experiment with changing the flakes to static objects once they land so they don’t roll.

You might also want to increase the friction on the flakes, so they “cling” to each other a bit more. This may (or may not) have the effect that you want, but it’s worth a try. :slight_smile:

Brent