Physics Problem

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- display.setStatusBar( display.HiddenStatusBar ) local width = display.actualContentWidth local height = display.actualContentHeight local background = display.newRect( width \* 0.5, height \* 0.5, width, height ) local physics = require( "physics" ) physics.start() local line = display.newRect( width \* 0.5, height - 64, width, 128 ) line:setFillColor( 0.1, 0.1, 0.1 ) physics.addBody( line, "static" ) local player = display.newRect( width \* 0.5, height \* 0.5, 64, 64 ) player:setFillColor( 0.93, 0.11, 0.14 ) physics.addBody( player ) player:setLinearVelocity( -100, 0 )

Why doesn’t player move continuously? It stops after two seconds.

That’s not how it works.  Friction and/or damping will stop the body from moving over time.  setLinearVelocity() is not continuous, it is instantaneous.

If you want the object to move at a continuous rate, call setLinearVelocity OR apply a force  in an enterFrame listener .

Suggestions:

  1. Read all the guides linked at the top of this documenation page: https://docs.coronalabs.com/api/library/physics/index.html

physics_guides.png

  1. Download my old examples and play with them (impulses & forces folders in the zip file; click colored boxes to run examples):

https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/Hangout%2081.zip

impulses.png forces.png

  1. Grab this example from my AskEd archive (in fact get the entire repository for fun):

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/08/impulsesForcesVelocitiesOhMy.zip

impulsesForcesVelocitiesOhMy.png

Entire RGFreeStuff repository (see AskEd folder for 400+ coded answers):

https://github.com/roaminggamer/RG_FreeStuff

The last example uses an OLD version of SSK, so if you go that route, be sure to use the latest (may not be compatible w/ example due to path/folder name changes):

https://roaminggamer.github.io/RGDocs/pages/SSK2/

You may find my actions lib useful, but honestly this is something you can do w/o anything extra like SSK.

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/actions1/

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/actions2/

How can I disable friction and damping? I tested my code with no gravity and then player was moving continuously. But I want to achieve this by not disabling gravity. Thanks…

Please read the docs/guides as suggested, it’s all there:

https://docs.coronalabs.com/api/library/physics/index.html

I keep the API docs linked on my browser bar,  (I refer to it all the time).

I know it seems like a lot, but you’ll need to read it and experiment a lot to learn this stuff.  Sorry.
 
You see if I just said this: 

local crate = display.newImage( "crate.png", 100, 200 ) physics.addBody( crate, {friction=0 } ) crate.linearDamping = 0

you’d skip all the learning and soon come back with a new question, no better ready to self-help.

Sorry for stealing your time… Thanks for help I will try to learn it myself.

Note: I don’t think gravity is actually the focus here,but if you want gravity on for some objects and off for others, you can make a dynamic physics object ignore gravity by setting it’s gravityScale to 0.

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

Don’t worry.  You’re not stealing my time.  I’m giving it.  However, I answer the way I do, because I know these kinds of questions:

  • are open-ended in nature
  • lead to more questions
  • are specific to the goals you have (which are hard for me to know as I’m not a mind reader), so it is hard for me to give you the perfect answer.

So, I typically give some info, but then encourage self learning while giving samples and sources to do that learning from.

Good luck on your journey.

PS - When you get bored or tired, take a peek here (all free):

https://forums.coronalabs.com/topic/74704-template-portfolio-release/

If you specify friction (to eliminate loss of linear velocity to angular velocity during “sliding” contacts) then you’ll need to specify bounce (aka restitution) also - set it to 1 to eliminate loss from non-elastic collision response.  (it’s not clear why overriding one default wipes out others, but it does, so once you start specifying one then it’s best to specify everything)

That’s not how it works.  Friction and/or damping will stop the body from moving over time.  setLinearVelocity() is not continuous, it is instantaneous.

If you want the object to move at a continuous rate, call setLinearVelocity OR apply a force  in an enterFrame listener .

Suggestions:

  1. Read all the guides linked at the top of this documenation page: https://docs.coronalabs.com/api/library/physics/index.html

physics_guides.png

  1. Download my old examples and play with them (impulses & forces folders in the zip file; click colored boxes to run examples):

https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/Hangout%2081.zip

impulses.png forces.png

  1. Grab this example from my AskEd archive (in fact get the entire repository for fun):

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/08/impulsesForcesVelocitiesOhMy.zip

impulsesForcesVelocitiesOhMy.png

Entire RGFreeStuff repository (see AskEd folder for 400+ coded answers):

https://github.com/roaminggamer/RG_FreeStuff

The last example uses an OLD version of SSK, so if you go that route, be sure to use the latest (may not be compatible w/ example due to path/folder name changes):

https://roaminggamer.github.io/RGDocs/pages/SSK2/

You may find my actions lib useful, but honestly this is something you can do w/o anything extra like SSK.

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/actions1/

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/actions2/

How can I disable friction and damping? I tested my code with no gravity and then player was moving continuously. But I want to achieve this by not disabling gravity. Thanks…

Please read the docs/guides as suggested, it’s all there:

https://docs.coronalabs.com/api/library/physics/index.html

I keep the API docs linked on my browser bar,  (I refer to it all the time).

I know it seems like a lot, but you’ll need to read it and experiment a lot to learn this stuff.  Sorry.
 
You see if I just said this: 

local crate = display.newImage( "crate.png", 100, 200 ) physics.addBody( crate, {friction=0 } ) crate.linearDamping = 0

you’d skip all the learning and soon come back with a new question, no better ready to self-help.

Sorry for stealing your time… Thanks for help I will try to learn it myself.

Note: I don’t think gravity is actually the focus here,but if you want gravity on for some objects and off for others, you can make a dynamic physics object ignore gravity by setting it’s gravityScale to 0.

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

Don’t worry.  You’re not stealing my time.  I’m giving it.  However, I answer the way I do, because I know these kinds of questions:

  • are open-ended in nature
  • lead to more questions
  • are specific to the goals you have (which are hard for me to know as I’m not a mind reader), so it is hard for me to give you the perfect answer.

So, I typically give some info, but then encourage self learning while giving samples and sources to do that learning from.

Good luck on your journey.

PS - When you get bored or tired, take a peek here (all free):

https://forums.coronalabs.com/topic/74704-template-portfolio-release/

If you specify friction (to eliminate loss of linear velocity to angular velocity during “sliding” contacts) then you’ll need to specify bounce (aka restitution) also - set it to 1 to eliminate loss from non-elastic collision response.  (it’s not clear why overriding one default wipes out others, but it does, so once you start specifying one then it’s best to specify everything)