Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to add friction with setGravity( 0, 0 ) (pool table / icehockey game)
Started by mail6860 May 07 2018 07:19 AM

3 replies to this topic
lineardamping friction

Best Answer roaminggamer , 07 May 2018 - 09:59 AM

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.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

mail6860

[GLOBAL: userInfoPane.html]
mail6860
  • Observer

  • 6 posts
  • Corona SDK

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 )


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,403 posts
  • Corona SDK

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



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,403 posts
  • Corona SDK

  Best Answer

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.



[TOPIC: post.html]
#4

mail6860

[GLOBAL: userInfoPane.html]
mail6860
  • Observer

  • 6 posts
  • Corona SDK

Thanks roaminggamer - you are my hero :-)




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: lineardamping, friction