Physics Forces

Discussion and feedback on Construct 2

» Tue Feb 04, 2014 3:21 pm

If I have 'Every Tick apply force 10' to an object... does this mean that if I was getting 60 frames per second and said object moves (let's say) 600 pixels in a second....

If I was only getting 30 frames a second, would the object have less force applied to it, and therefore move half the speed, and travel half the distance?

I only ask because I believe this is happening to my game. On my mobile device, I'm only getting 30fps, and everything else is set up with DT, but I can't do that with physics, as I believe @Ashley has already said that physics already has DT applied. I have frame-rate independence on, but I'm still getting slow speeds. If I use gravity, on the other hand, the item drops at normal speed no matter the frame rate. It just appears to be forces that are affected.

Just wondering if anyone else has experienced this, and come up with a clever way to get around it.
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758

» Tue Feb 04, 2014 7:01 pm

I have tried to keep away from applying forces in physics because I suspect that you're right and that framerate does make a difference to an object's behavior. Instead I always apply impulses because, by implication (force x time), there has to be a consideration of dt so any framerate problem should be more readily smoothed over by the physics engine. I'm not certain how box 2d implements this but that could be the solution you're after.

Edit: Just to add that the more I think about this the more convinced I am that you should always strive to use impulses when looking to cause an effect on an object, if you can get away with it. The effects of an impulse will be different to a force but the results might be more reproducible - a constant force applied over 1 second might have framerate application errors whereas an impulse of equivalent magnitude should always have the same effect. The difference, of course, is the impulse is instantaneous whereas the force can cause a progressive change of behavior, so they are not always interchangeable. Just my 2 pence... I'm sure @Ashley could clarify for certain.Colludium2014-02-04 19:06:35
Learning other engines, but C2 still rocks.
B
80
S
22
G
95
Posts: 2,415
Reputation: 57,667

» Tue Feb 04, 2014 7:56 pm

@Colludium

Sadly I'm using force to allow me to alter the direction of gravity on an object. This means a slower, more progressive look and feel is required.

Thank you for your message though. I will look into how I could perhaps use impulse.
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758

» Tue Feb 04, 2014 8:30 pm

@AnD4D,

Ahhh - something subtle like a gravity force won't be so easy to 'fix', at least not for my brain! The only thing I can think of doing would be to forcibly accelerate the object by changing the physics x and y velocity vectors - the same effect as a force but taking dt into account. It might be convoluted and I know that forcing velocities on box 2d can upset it, but here goes:

every tick:
object - set physics velocity
x component = object.physics.velocityx + dt*force*cos(force_angle)
y component = object.physics.velocityy + dt*force*sin(force_angle)

where force_angle is the vector direction you want the force to act in. It might be worth a try...
Learning other engines, but C2 still rocks.
B
80
S
22
G
95
Posts: 2,415
Reputation: 57,667

» Thu Feb 06, 2014 1:03 pm

@Colludium

Sorry for the delay! Thank you for your message. I've given it a go, but sadly it doesn't appear to do anything at all to the motion.

I've also tried to just add DT to my current force, but on my mobile device gravity is suddenly really powerful, so things are barely able to lift from the floor.

It's frustrating, seeing as my game has been finished since November (really finished since September, but made a few tweaks). A few versions of C2 back I was getting 55fps, so it wasn't a big deal, then it suddenly went down to 15, and has slowly worked its way back up to 30.

If I could just get DT working correctly for my physics, I wouldn't mind so much.

Anyone have any ideas on how to sort this out??
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758

» Thu Feb 06, 2014 3:35 pm

@AnD4D,

It was a bit of a long shot - I'm sorry it doesn't work. I presume you're using cocoonjs - is asm.js is out of the question? I haven't tried it for a couple of months because of the teething problems but the use of a different and better optimized engine might work...
Learning other engines, but C2 still rocks.
B
80
S
22
G
95
Posts: 2,415
Reputation: 57,667

» Fri Feb 07, 2014 6:33 am

@Colludium

Yeah, I'm using CocoonJS's physics. I'm not sure how much of a difference it will make. asm.js doesn't allow (as far as I can tell) the disable physics collision command... which, sadly, my game relies quite heavily on.

Since finishing this game, I've finished 2 others, published one, and working on 2 more. It's just a shame because this is the game I'm most proud of. I keep waiting thinking that things will sort themselves out.

Do you think if I used 'every 0.01 seconds' instead of tick it would work better? I'm worried it wouldn't make a difference, but may interfere with my game somehow.
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758