physics based collision detection not working?

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
gladius2metal
Prole
Posts: 26
Joined: Thu Nov 22, 2012 2:08 am

Re: physics based collision detection not working?

Post by gladius2metal »

Remember that getVelocity returns pixels per second, not meters per second.
ahh, thx!

well, I think the main problem is that I don't know what unit type "lineardamping" has or what its value actually represents neither love2d API nor the box2d manual are very helpful here :(
https://love2d.org/wiki/Body:getLinearDamping
Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1. I generally do not use linear damping because it makes bodies look floaty.
http://www.box2d.org/manual.html

is lineardamping = 0.5 like 0.5 kg/m or something completely different?
User avatar
Przemator
Party member
Posts: 107
Joined: Fri Sep 28, 2012 6:59 pm

Re: physics based collision detection not working?

Post by Przemator »

Linear Damping is a non-realistic parameter. If you decide to slow down your body with forces, disable linear damping.

I know what you mean by lack of documentation, I looked for it myself. Finally, I had to check the Box2D source code XD.

Code: Select all

// Apply damping.
// ODE: dv/dt + c * v = 0
// Solution: v(t) = v0 * exp(-c * t)
// Time step: v(t + dt) = v0 * exp(-c * (t + dt)) = v0 * exp(-c * t) * exp(-c * dt) = v * exp(-c * dt)
// v2 = exp(-c * dt) * v1
// Taylor expansion:
// v2 = (1.0f - c * dt) * v1

v *= b2Clamp(1.0f - h * b->m_linearDamping, 0.0f, 1.0f);
So in Lua/Love this translates to:

Code: Select all

velocity = velocity * clamp(1 - dt * linear_damping, 0, 1)
Clamp I'm sure you know how it works, it's just math.min(math.max()) bottom-top limiter.

This thing gets called each world:update(). So Let's say dt = 1/60 and damping = 6. Then:

Code: Select all

v(n) = v(n-1) * (1 - 1 / 60 * 6) = v(n-1) * 0.9
So you get a geometric series which is the same as:

velocity(time) = initial_velocity * 0.9 ^ time

And it will look like this: http://www.wolframalpha.com/input/?i=y+%3D+10+*+0.9%5Ex
User avatar
gladius2metal
Prole
Posts: 26
Joined: Thu Nov 22, 2012 2:08 am

Re: physics based collision detection not working?

Post by gladius2metal »

thx, this just got more complicated than before :o

well, the main problem is: I want to know the max speed of my physics objects in order to display them to the player (e.g. when he buys a ship). Is there a solution calculating this value when I am using linearDamping or not?
User avatar
Przemator
Party member
Posts: 107
Joined: Fri Sep 28, 2012 6:59 pm

Re: physics based collision detection not working?

Post by Przemator »

gladius2metal wrote:thx, this just got more complicated than before :o

well, the main problem is: I want to know the max speed of my physics objects in order to display them to the player (e.g. when he buys a ship). Is there a solution calculating this value when I am using linearDamping or not?
How about making this more feature rich. Instead of specifying max speed, you could have a choice of engines with different thrust values and a choice of bodies with various drag coefficients. Then the player could buy a good engine with poor body (good acceleration / low top speed) or poor engine with a good body (poor acceleration / high top speed).

Also, I should warn you that Box2D has it's own speed limit, I think it is set to about 120 m/s (about 430 km/h). So if you set the meter size too low, you may reach this limit and then you just can't go faster.
User avatar
gladius2metal
Prole
Posts: 26
Joined: Thu Nov 22, 2012 2:08 am

Re: physics based collision detection not working?

Post by gladius2metal »

Przemator wrote: How about making this more feature rich. Instead of specifying max speed, you could have a choice of engines with different thrust values and a choice of bodies with various drag coefficients. Then the player could buy a good engine with poor body (good acceleration / low top speed) or poor engine with a good body (poor acceleration / high top speed).
I want to finish the game ;) but something similar more simple is planned. Basically, I want to use as much features out of the box as possible, hence I use lineardamping for now instead of applying a custom drag coefficient. Especially, since in the early stage I don't want waste time on "perfecting" too much that makes it harder to scrap unnecessary features etc.
Right now, I think the fly behavior for the ship is good and makes fun. I guess I will find some way to determine the max speed later or use a different approach anyway.

Przemator wrote: Also, I should warn you that Box2D has it's own speed limit, I think it is set to about 120 m/s (about 430 km/h). So if you set the meter size too low, you may reach this limit and then you just can't go faster.
thx for the info
User avatar
Przemator
Party member
Posts: 107
Joined: Fri Sep 28, 2012 6:59 pm

Re: physics based collision detection not working?

Post by Przemator »

Well if it's max speed you're after then why not try this:

Code: Select all

if love.keyboard.isDown("up") and ship:getSpeed() < 30 then ship.body:applyForce(...) end
This condition will cut off the engine when you exceed the speed limit. The downside is that it will not settle at top speed smoothly.

PS Regarding the other thread, I totally overlooked the Body:setActive() so count me in for the blindness :P.
User avatar
gladius2metal
Prole
Posts: 26
Joined: Thu Nov 22, 2012 2:08 am

Re: physics based collision detection not working?

Post by gladius2metal »

Przemator wrote:Well if it's max speed you're after then why not try this:

Code: Select all

if love.keyboard.isDown("up") and ship:getSpeed() < 30 then ship.body:applyForce(...) end
the main point is that I want the use the current behavior without tinkering too much. With this solution I hack a top speed into instead of getting - via calculation - the correct value that the physics engine produces anyway. Right now, everything is working and I like the set, BUT I can't (yet) determine the maximum velocity of the ships.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests