## Decrease velocity

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

### Decrease velocity

Is there a built-in thing that gradually slows down the object, its linear velocity?

akopyl
Prole
Posts: 21
Joined: Fri Jun 27, 2014 1:20 pm

### Re: Decrease velocity

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

Do bodies have xVel?

i tried to do

Code: Select all

ball.fixture:setFriction(10)
but it didn't slow the ball down.

pgimeno
Party member
Posts: 1818
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Decrease velocity

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

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()?

pgimeno
Party member
Posts: 1818
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Decrease velocity

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()).

### Who is online

Users browsing this forum: No registered users and 5 guests