Physics Forces

0 favourites
  • 7 posts
From the Asset Store
Build a thrilling space station scenario with these level assets and characters.
  • Question about physics forces.

    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.

  • 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.

  • 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.

  • 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...

  • 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 had: Robert.Physics.VelocityX+dt*(Robert.Physics.Mass*Gravity)*cos(GravityAngle)

    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??

  • 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...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)