## Stabilizing Physics

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

### Stabilizing Physics

Hello fellow lövers!

I'm writing a small little game and I'm trying to avoid using the love physics system because of the issue of having multiple square colliders directly adjacent to each other causing weird collision issues.

So I have a pretty solid physics system but the problem is depending how the game is running ( between my 600fps framerate on it, or the 60 I get when recording, for example ) the physics act oddly.

So when I jump normally, it's a reasonable jump. You just jump up and then glide down depending on I set the gravity constant to. But if I have the slower framerate, I barely jump, and gravity is affected as well, however, moving left to right and the air resistance moving left and right stays the same.

Is there any way to stabilize the physics between all framerates and/or DTs? Thank you!
https://github.com/ebernerd- where you can find all my work.

Nixola
Inner party member
Posts: 1944
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

### Re: Stabilizing Physics

You basically want to do something like this to update at a fixed timestep:

Code: Select all

timer = 0
interval = 1/60
love.update = function(dt)
timer = timer + dt
while timer > interval do
physics.update(interval)
timer = timer - interval
end
end
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
li = love.image
lg = love.graphics

MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

### Re: Stabilizing Physics

This did better but still did not solve my issue. Before the jumping would be lower depeding on the speed, but now if the framerate is lower, so is the gravity inflicted on the player. I'll look into this further.

It's funny because I tried doing something like this before but actually didn't update using the interval I updated using DT in that timer setting so it literally did nothing.

EDIT: this also makes the game less stable. It seems to "flicker" a lot more, meaning the physics are more jittery. Unless I'm still doing it wrong.
https://github.com/ebernerd- where you can find all my work.

Nixola
Inner party member
Posts: 1944
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

### Re: Stabilizing Physics

Are you sure you're properly using dt in every calculation?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
li = love.image
lg = love.graphics

MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

### Re: Stabilizing Physics

I'm not sure if I'm using DT correctly.

My code's a mess and the game isn't 100% optimized in terms of efficiency, but it runs.

Moon world breaks. I'm working on a fix to that, I promise

Controls (configurable in the options menu:)
A-D: move character
Space: Jump
Left Click: break block
Rclick: place block
Attachments
Game.love
For Love 0.9.1 ( which I think include 0.9.2? )
https://github.com/ebernerd- where you can find all my work.

MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

### Re: Stabilizing Physics

Basically I want physics to update at the same speed no matter what the framerate is, which is not what's happening right now. :\
https://github.com/ebernerd- where you can find all my work.

MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

### Re: Stabilizing Physics

Case closed. After a lot of discussion with one of my friends, I fixed it. Thanks for your help!
https://github.com/ebernerd- where you can find all my work.

### Who is online

Users browsing this forum: No registered users and 20 guests