physics - Air Resistance/Friction

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.
Post Reply
Blady
Prole
Posts: 4
Joined: Sat Nov 20, 2010 10:08 am

physics - Air Resistance/Friction

Post by Blady »

I got a problem with physics module. There are not air resistance O.o I'm thinking how do this by another way, but it have to be depends on delta time.

For every objects, program perform it:

Code: Select all

local sx, sy = body:getLinearVelocity()
sx = sx * self.worldAirResistance*dt
body:setLinearVelocity( sx, sy )
Data is:
self.worldAirResistance = 0.9

But (0.9 * dt) is a very small value, it make that Air Resistance is too strong.

I need it for my platform game, for player object. Any ideas?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: physics - Air Resistance/Friction

Post by Robin »

There is a good way to do this, with body:setLinearDamping(damping). You only have to do this once after you create the body.
Help us help you: attach a .love.
Blady
Prole
Posts: 4
Joined: Sat Nov 20, 2010 10:08 am

Re: physics - Air Resistance/Friction

Post by Blady »

Ya, it works :crazy: but horizontally and vertically. :o And it look funny when Player slowly fall after jump. How do this just in horizontal?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: physics - Air Resistance/Friction

Post by Robin »

Blady wrote:Ya, it works :crazy: but horizontally and vertically. :o And it look funny when Player slowly fall after jump. How do this just in horizontal?
Well, I think you can adjust gravity to pull stronger, so on the whole it seems like before.
Help us help you: attach a .love.
User avatar
ghostwriter
Prole
Posts: 38
Joined: Sat Dec 11, 2010 11:08 pm

Re: physics - Air Resistance/Friction

Post by ghostwriter »

If you want to calculate drag effects manually and not use the method Robin suggested, the correct way would probably be to calculate it by means of Force, not by directly manipulating the Velocity.

Code: Select all

local sx, sy = body:getLinearVelocity()
local fx = -sx * self.worldAirResistance -- the drag *force* is opposite and proportional to the velocity
body:applyForce(fx, 0)
Post Reply

Who is online

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