insantly stop a body in love.physics

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

insantly stop a body in love.physics

Post by Doctory »

how would i stop a body in love.physics? im making a platformer game and i need the player not to slide around
User avatar
ivan
Party member
Posts: 1912
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: insantly stop a body in love.physics

Post by ivan »

For sliding over platforms we use friction (from 0 to 1)
For lowering the velocity over time (even while in the air) we use linarDamping and angularDamping (from 0 to positive infinity)
Another option is to manually set the linear/angular velocity to 0 but this will produce strange looking collisions.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: insantly stop a body in love.physics

Post by Doctory »

when i use :setFriction(1) it throws an error on me that its a nil value
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: insantly stop a body in love.physics

Post by arampl »

Maybe object before colon is not fixture?
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: insantly stop a body in love.physics

Post by Doctory »

it most certainly is a fixture
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: insantly stop a body in love.physics

Post by arampl »

Then more code needed. ":setFriction(1)" is not enough. What else can give you nil? Of course not "1". And "setFriction" is the right name for the method.
User avatar
zorg
Party member
Posts: 3449
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: insantly stop a body in love.physics

Post by zorg »

According to the wiki, only Shapes, Fixtures and Contacts have setFriction methods; the code should only return an error about that being nil if the object's not one of those.
You could post in the relevant piece of code as arampl mentioned.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: insantly stop a body in love.physics

Post by Doctory »

Code: Select all

player.body = love.physics.newBody(world, player.spawnpoint.x, player.spawnpoint.y, "dynamic")
player.shape = love.physics.newRectangleShape(20, 20)
player.fixture = love.physics.newFixture(player.body, player.shape):setUserData("player")
putting setFriction on shape or the fixture just returns a nil error
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: insantly stop a body in love.physics

Post by arampl »

I think you should split the last line into two:

Code: Select all

player.fixture = love.physics.newFixture(player.body, player.shape)
player.fixture:setUserData("player")
Then you'll be able to use setFriction with player.fixture.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: insantly stop a body in love.physics

Post by Doctory »

arampl wrote:I think you should split the last line into two:

Code: Select all

player.fixture = love.physics.newFixture(player.body, player.shape)
player.fixture:setUserData("player")
Then you'll be able to use setFriction with player.fixture.
god bless you
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests