How to add friction with setGravity( 0, 0 ) (pool table / icehockey game)

Hi folks,

I’m quite new to Corona and I try to develop a icehockey-like game (view from top). Thus, I don’t need gravity. If I want to push the puck - wo can I simulate the friction of the ice in this mode?

I use linearDamping but the puck won’t reduce it’s speed over time. What am I doing wrong?

Thanks.

local physics = require "physics" physics.start() physics.setGravity( 0, 0 ) local backGroup = display.newGroup(); local stoneGroup = display.newGroup(); local ground = display.newImageRect(backGroup, "assets/images/background-ice.png", 723, 1400 ) ground.x = display.contentCenterX ground.y = display.contentCenterY local activeStone = display.newImageRect( stoneGroup, "assets/images/puck.png", 150, 150 ) activeStone.x = display.contentCenterX activeStone.y = display.contentHeight activeStone.linearDamping = 100 physics.addBody( activeStone, "dynamic", { radius = 150, bounce = 0 } ) local function pushPuck () activeStone:applyForce( 0, - 100, activeStone.x, activeStone.y) end activeStone:addEventListener( "tap", pushPuck )

You’re thinking about the problem incorrectly.

Friction is between bodies.  The screen/world/background is not a body.

Use linear damping to get the result you want:

https://docs.coronalabs.com/api/type/Body/linearDamping.html

Yes, I see you have linear damping set, but you are doing it at the wrong time.  (And your value is way too high).

You cannot modify physics properties of a body till AFTER you add the body.

You have this:

activeStone.linearDamping = 100 physics.addBody( activeStone, "dynamic", { radius = 150, bounce = 0 } )

You need this:

physics.addBody( activeStone, "dynamic", { radius = 150, bounce = 0 } ) activeStone.linearDamping = 1

Don’t worry.  We have all done this at one time or another.

Thanks roaminggamer - you are my hero :slight_smile:

You’re thinking about the problem incorrectly.

Friction is between bodies.  The screen/world/background is not a body.

Use linear damping to get the result you want:

https://docs.coronalabs.com/api/type/Body/linearDamping.html

Yes, I see you have linear damping set, but you are doing it at the wrong time.  (And your value is way too high).

You cannot modify physics properties of a body till AFTER you add the body.

You have this:

activeStone.linearDamping = 100 physics.addBody( activeStone, "dynamic", { radius = 150, bounce = 0 } )

You need this:

physics.addBody( activeStone, "dynamic", { radius = 150, bounce = 0 } ) activeStone.linearDamping = 1

Don’t worry.  We have all done this at one time or another.

Thanks roaminggamer - you are my hero :slight_smile: