Physics problem

Hi,
I have one problem. In my physics game, whenever I hit edge of some physics object(rectangle in this case) with my player, player starts sliding in direction where he was hit , and he does it without stopping, like he is on ice and like there are no physics. How do I solve this? :smiley:

Your question is too general. You need to provide more information, like a screenshot or a drawing and possibly some code.

when you create a Physics object with physics.addBody()

try setting the friction this will slow the item, also look at the other options available here.

http://docs.coronalabs.com/api/library/physics/addBody.html

Larry

larry i am working with balsaj and we already tried incresing friction but it doesnt help, i can only describe problem with a video, because its very specific,terrein in the game is made of rectengles and only when i hit its edge(smaller edge) object starts going in other direction… and ground acts like there is no friction, anyway thanks for the answer :slight_smile:

one update on the problem, when i disable bounce problem is half solved but still i think there is a broblem in joystick module we use(module by Mike Dogan), when object hits a wall its rotating and when i relese joystick it bounces of back,is there any way for object to just stop when it hits anything? 

Hi @vukstajkic,

Just a couple notes:

  1. For friction to work, make sure that both bodies have at least some friction. If one body has 0 friction (or extremely low) then it won’t matter if the other has high friction… it will still slide like it’s on ice.

  2. You can prevent a body from rotating by setting “.isFixedRotation” on it.

[lua]

myBody.isFixedRotation = true

[/lua]

  1. You can stop an object by simply setting its linear velocity values to 0:

[lua]

myBody:setLinearVelocity( 0,0 )

[/lua]

Hope this helps,

Brent

Your question is too general. You need to provide more information, like a screenshot or a drawing and possibly some code.

when you create a Physics object with physics.addBody()

try setting the friction this will slow the item, also look at the other options available here.

http://docs.coronalabs.com/api/library/physics/addBody.html

Larry

larry i am working with balsaj and we already tried incresing friction but it doesnt help, i can only describe problem with a video, because its very specific,terrein in the game is made of rectengles and only when i hit its edge(smaller edge) object starts going in other direction… and ground acts like there is no friction, anyway thanks for the answer :slight_smile:

one update on the problem, when i disable bounce problem is half solved but still i think there is a broblem in joystick module we use(module by Mike Dogan), when object hits a wall its rotating and when i relese joystick it bounces of back,is there any way for object to just stop when it hits anything? 

Hi @vukstajkic,

Just a couple notes:

  1. For friction to work, make sure that both bodies have at least some friction. If one body has 0 friction (or extremely low) then it won’t matter if the other has high friction… it will still slide like it’s on ice.

  2. You can prevent a body from rotating by setting “.isFixedRotation” on it.

[lua]

myBody.isFixedRotation = true

[/lua]

  1. You can stop an object by simply setting its linear velocity values to 0:

[lua]

myBody:setLinearVelocity( 0,0 )

[/lua]

Hope this helps,

Brent

I have a quaestion to ask regarding Brent Sorentinos answer. When i type setLinearVelocity(0,0) it does nothing. I even stop the physics engine and it wont stop the body. Graity is zero. Even if i switch the order of physics.stop and setLinearVelocity(0,0) the code does not work. Here is the code. Help me :frowning:

local physics = require (“physics”)

physics.start()

physics.setGravity(0,0)

local square = display.newRect(100,100,20,20)

physics.addBody(square, “Dynamic”)

square:setLinearVelocity(0,300)

if square.y >= 600 then

     square:setLinearVelocity(0)

     physics.stop()

end

Hi @zvonimir.kristo010,

First thing, the body type should be “dynamic”, not"Dynamic" (notice the case-sensitive difference).

Second, when you call setLinearVelocity(), you must provide both values at 0, not just one. So it should be:

[lua]

square:setLinearVelocity(0,0)

[/lua]

Brent

I have a quaestion to ask regarding Brent Sorentinos answer. When i type setLinearVelocity(0,0) it does nothing. I even stop the physics engine and it wont stop the body. Graity is zero. Even if i switch the order of physics.stop and setLinearVelocity(0,0) the code does not work. Here is the code. Help me :frowning:

local physics = require (“physics”)

physics.start()

physics.setGravity(0,0)

local square = display.newRect(100,100,20,20)

physics.addBody(square, “Dynamic”)

square:setLinearVelocity(0,300)

if square.y >= 600 then

     square:setLinearVelocity(0)

     physics.stop()

end

Hi @zvonimir.kristo010,

First thing, the body type should be “dynamic”, not"Dynamic" (notice the case-sensitive difference).

Second, when you call setLinearVelocity(), you must provide both values at 0, not just one. So it should be:

[lua]

square:setLinearVelocity(0,0)

[/lua]

Brent