Decrease velocity

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
TheSoftWaffle
Prole
Posts: 3
Joined: Mon Oct 07, 2019 4:17 pm

Decrease velocity

Post by TheSoftWaffle »

Is there a built-in thing that gradually slows down the object, its linear velocity?
User avatar
akopyl
Prole
Posts: 21
Joined: Fri Jun 27, 2014 1:20 pm

Re: Decrease velocity

Post by akopyl »

Usually we call it friction.
Here's a simple way to do it:

Code: Select all

player.xVel = player.xVel * (1 - math.min(player.friction*dt, 1))
TheSoftWaffle
Prole
Posts: 3
Joined: Mon Oct 07, 2019 4:17 pm

Re: Decrease velocity

Post by TheSoftWaffle »

Do bodies have xVel?

i tried to do

Code: Select all

ball.fixture:setFriction(10)
but it didn't slow the ball down.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Decrease velocity

Post by pgimeno »

See Body:setLinearDamping.

Friction applies to contact between two bodies.
TheSoftWaffle
Prole
Posts: 3
Joined: Mon Oct 07, 2019 4:17 pm

Re: Decrease velocity

Post by TheSoftWaffle »

Thanks, will check out
It does that with the y coords too.
Can i do that with only x?
Btw i am new to lua, how can i only get the y value from getLinearVelocity()?
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Decrease velocity

Post by pgimeno »

TheSoftWaffle wrote: Thu Oct 10, 2019 5:24 pm Can i do that with only x?
Not with any existing function. You need to implement damping yourself, using e.g. applyForce proportional to current x velocity.
TheSoftWaffle wrote: Thu Oct 10, 2019 5:24 pm Btw i am new to lua, how can i only get the y value from getLinearVelocity()?
If you absolutely must, you can use select(2, yourbody:getLinearVelocity()).
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests