Decrease velocity
-
- 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?
Re: Decrease velocity
Usually we call it friction.
Here's a simple way to do it:
Here's a simple way to do it:
Code: Select all
player.xVel = player.xVel * (1 - math.min(player.friction*dt, 1))
-
- Prole
- Posts: 3
- Joined: Mon Oct 07, 2019 4:17 pm
Re: Decrease velocity
Do bodies have xVel?
i tried to do but it didn't slow the ball down.
i tried to do
Code: Select all
ball.fixture:setFriction(10)
-
- 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()?
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()?
Re: Decrease velocity
Not with any existing function. You need to implement damping yourself, using e.g. applyForce proportional to current x velocity.
If you absolutely must, you can use select(2, yourbody:getLinearVelocity()).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()?
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests