change friction of an object

Hi,

Is it me or there’s no way to change the friction of an object?

I wish a:
mySprite:setFriction(0)

How can it be missing?

Cheers

Romu [import]uid: 78547 topic_id: 12936 reply_id: 312936[/import]

Set that with physics. [import]uid: 13560 topic_id: 12936 reply_id: 47438[/import]

It’s not “missing”, as lano78 said, it’s a part of physics. An image that isn’t a physics body cannot have friction - that wouldn’t make any sense. [import]uid: 52491 topic_id: 12936 reply_id: 47456[/import]

Yes I do understand that.

And I did add a body to my sprite:
physics.addBody(character, “dynamic”, { density=1, friction=0, bounce=0.2 })

Now I want to be able to change the friction on the fly, because that’s how it should be done. And that’s how it is done with Box2D.

You get the fixture and you change the friction. Now the fixture in Corona is mixed in the sprite, so again. How do I change the friction of an object?

Do I need to use addBody again with a different friction parameter? In this case, how I delete/reset/remove the previously created body from the sprite?

Thanks for the help.

Romu

[import]uid: 78547 topic_id: 12936 reply_id: 47470[/import]

[code]
local physics = require(“physics”)
physics.start()
physics.setGravity(0, 9.8)
physics.setDrawMode(“hybrid”) – this will let you see how physics objects interact

system.setAccelerometerInterval( 50 )

local function tilt( event )
physics.setGravity( ( 9.8 * event.xGravity ), ( -9.8 * event.yGravity ) )
end
Runtime:addEventListener( “accelerometer”, tilt )

– Create borders around the screen so mySprite can’t fall off screen.
– Here I preset the physics properties because I am lazy and don’t like to type too much.
borderProperties = { density = 0.5,friction = 0.5, bounce = 0.2 }
– (x, y , width, height)
local borderTop = display.newRect( 0, 0, display.contentWidth, 0 )
borderTop:setFillColor( 110, 110, 110)
physics.addBody( borderTop, “static”, borderProperties )

local borderBottom = display.newRect( 0, display.contentHeight, display.contentWidth, 0 )
borderBottom:setFillColor( 110, 110, 110)
physics.addBody( borderBottom, “static”, borderProperties )

local borderLeft = display.newRect( 0, 0, 0, display.contentHeight )
borderLeft:setFillColor( 110, 110, 110)
physics.addBody( borderLeft, “static”, borderProperties )

local borderRight = display.newRect( display.contentWidth, 0, 0, display.contentHeight )
borderRight:setFillColor( 110, 110, 110)
physics.addBody( borderRight, “static”, borderProperties )

– Your image, position it in the center of the screen.
–local mySprite = display.newImage(“mySprite.png”, display.contentWidth*0.5, display.contentHeight*0.5 )
local mySprite = display.newRect( display.contentWidth*0.5, display.contentHeight*0.5, 32, 32)
– Here we set the physics properties for the object,
physics.addBody (mySprite, “dynamic”, {density = 0.5, friction = 10.0, bounce = 0.5} )

[/code] [import]uid: 13560 topic_id: 12936 reply_id: 47476[/import]

DELETED as it is irrelevant now. [import]uid: 27965 topic_id: 12936 reply_id: 47484[/import]

lano78, you post doesn’t answer the question at all… thanks anyway.

And calebr2048, why did you remove your post? it think it was relevant actually :slight_smile:

[import]uid: 78547 topic_id: 12936 reply_id: 47487[/import]

My post was for the friction question, you just happened to ask another question before I answered the first one.

On the 2nd question, I haven’t tried changing it on the fly like you want. I think there was a thread about this topic a few days ago, try searching for it.
[import]uid: 13560 topic_id: 12936 reply_id: 47488[/import]

romu,
Sorry, I deleted my post in haste since I’m at work and in a hurry. Here it is (from memory) in case it is indeed deemed useful to anyone.

I have never done this myself but I believe you would have to create all objects individually (with different friction settings) and create a function that would swap the objects as needed. One way I can think of to do it might be something like this:

  1. Load all images and create their corresponding physics bodies and make them all invisible sensors
  2. Make the object you want to use visible and set isSensor to false
  3. To switch objects make the current object an invisible sensor and repeat step 2 for the object you want to use

I don’t have a code sample of this but it should be pretty simple to implement. [import]uid: 27965 topic_id: 12936 reply_id: 47498[/import]