Physics based controls and delta time frustration

Get help using Construct 2

Post » Sat May 11, 2013 10:49 am

Physics based controls and delta time frustration...

I have a physics object, which is affected by gravity. I accellerate it using a physics impulse triggered by pressing a button.

Now I have the very frustrating problem, that accelleration is varying extremely on different frame rates (different devices) even though I switched the physics behaviour to "framerate independent"

Same goes for rotation(when applying torque to the object)

My theory on this problem is, that the button press triggers the impulse every tick... So when running at 60FPS I have 60 impulses added to my object per second and on 30FPS I have 30 impulses added to my object. I tried to fix this using the dt-expression on the value for my accelleration ( acc * dt ) adding the same amount of thrust over time... but it didn't work. Accelleration still varies extremely...

So what can I do to fix this?
B
6
S
2
G
2
Posts: 31
Reputation: 1,288

Post » Sat May 11, 2013 12:54 pm

If you use

Button: "On clicked" => Sprite : "Apply Physics Impulse towards position"

it will only trigger once per click.
B
7
S
1
G
1
Posts: 32
Reputation: 1,016

Post » Sat May 11, 2013 2:30 pm

I've tried a bunch of different stuff to make the physics movement behave similarly with different frame rates but it's pretty awkward

a lower frame rate means the resulting velocity from apply force/impulse is much bigger, so you jump higher for example

something I experimented with and ended up keeping was making instance variables on each physics object, 'forceX' and 'forceY' and instead of 'apply force..' i use 'add to forceX'/add to forceY instead. and at the very end of the events sheet, it sets the velocity X to it's current velocity X plus the forceX value.. and then sets the forceX variable back to 0 for the next tick. Same for ForceY

now I dont know for sure whats going on under the hood, but i guess this means it's not doing a bunch of force iterations each tick, just one. The effect this has is that a lower frame rate means you jump slightly lower instead of higher (the difference is lessened too). Which is arguably better.. just try your best to make the game run at a consistent 60 fps. and maybe let the player know that 60 fps is really how it should be played.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Sat May 11, 2013 2:43 pm

[QUOTE=Prox] If you use

Button: "On clicked" => Sprite : "Apply Physics Impulse towards position"

it will only trigger once per click.[/QUOTE]

Thanks, but this one won't help in my case, because I don't need a single impulse. I want the sum of the impulses applied over time to be the same on any framerate.
B
6
S
2
G
2
Posts: 31
Reputation: 1,288

Post » Sat May 11, 2013 3:00 pm

@keepee: Thanks a lot for your reply, this one sounds quite promising and I will give it a shot.

In the meantime I kept on experimenting some more and it looks like my impulses are working out so far...

Framerate independent movement activated AND dt on my impulse gives me satisfying results... must have overlooked this earlier because rotation still won't work as it should:

I'm rotating my object by applying torque

without dt rotation on lower framerates is much too slow and with dt rotation on lower framerates is much too fast.
When measuring the angular velocity of my Sprite using "Sprite.Physics.AngularVelocity" WITHOUT dt I get the exact same values on all framerates, while still on lower framerates my sprite is rotating much much slower than on 60FPS.

This seems odd, because the manual says AngularVelocity outputs "The current angular velocity (rate of rotation) of the physics object, in degrees per second." and not degrees per tick or something.

So I'm still struggling^^
B
6
S
2
G
2
Posts: 31
Reputation: 1,288

Post » Sat May 11, 2013 3:00 pm

If you want, upload your project file so i can take a look at it. My current project use a lot physics too, maybe i can find your mistake.
B
7
S
1
G
1
Posts: 32
Reputation: 1,016

Post » Sat May 11, 2013 3:39 pm

[QUOTE=AndyKayJah]
This seems odd, because the manual says AngularVelocity outputs "The current angular velocity (rate of rotation) of the physics object, in degrees per second." and not degrees per tick or something.[/QUOTE]


The difference is that you are directly setting the angular velocity... like forcing it to to turn at this speed on every single tick...

whereas applying torque every tick will 'add on' to the ang veloc every tick, and this is where the torque force will be affected by delta time and subsequently affect the outcome ang veloc

the same is true for using 'set velocity' instead of 'apply force'
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Sat May 11, 2013 3:39 pm

[QUOTE=Prox] If you want, upload your project file so i can take a look at it. My current project use a lot physics too, maybe i can find your mistake. [/QUOTE]

The only mistake I made was to test on low end computers ;) so far everything worked perfectly, but anything below 30FPS is a complete mess.
B
6
S
2
G
2
Posts: 31
Reputation: 1,288

Post » Sat May 11, 2013 3:46 pm

@keepee: sorry, I think you got me wrong...

I used "apply torque" to spin my object and Sprite.Physics.Angular Velocity to measure the max rotation speed (got angular damping). And I used (or used not) the dt in the apply torque action...

apply torque with dt > spinning way too fast on low framerate
apply torque without dt > spinning way too slow on low framerates, but displaying the same angular velocity like on 60FPS
B
6
S
2
G
2
Posts: 31
Reputation: 1,288

Post » Sat May 11, 2013 3:54 pm

ah i see, my bad.

although you could actually try what I said and see if it works for you.. depending on your context i guess...

I've set my characters collision object as a circle, and to move left and right it sets angular velocity clockwise or anticlockwise. It actually works pretty good.. Changing the friction adjusts the inertia.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Next

Return to How do I....?

Who is online

Users browsing this forum: DemantDigitalArt, Unconnected and 30 guests