How do I calculate best method to slow down object inside a given layout width?

0 favourites
  • 4 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello there!

    So here is the thing:

    I created a sliding game, where you have to push objects to an specific position. The Layout Width is 20000. The Objects have a physics behaviour on it. Everything in this behaviour is set to zero, because "linear damping" or the "friction" parameter are not that precise to handle.

    I have a strength bar, where you can set the strenght, the object will be pushed by impulse. It generates a value from 0 between 100. This value has to be multiplicated with 1000, because otherwise it would be to less impulse.

    Now - because i have no friction or linear damping - i want to slow down the object relative to the impulse. the maximum impulse value (100 * 1000) should match the length of the Layout (20000).

    I slow down the object with : Object.physics.velocityX - 15. But this is hard coded. there should be a dynamic value, which matches the Layout Width.

    If you give the maximum impulse (100000), the Object should stop on positionX 20000. If i give just 50 * 1000 = 50000 impulse - the object should slide to position 10000 and so on.

    Do someone knows the math?

    Thx!

    Tagged:

  • Here’s the math for it where dist is the distance to move before stopping and f is the braking force.

    Global number f = -200

    Global number dist = 2000

    Start of layout

    — apply impulse self.mass*sqrt(-2*dist*f/self.mass)

    Velocityx > 0

    — apply force f

    Anyways that would work fairly well. However the units are off with the physics behavior. Here is the info on how to convert the units so the formulas above would work.

    construct.net/en/forum/construct-2/general-discussion-17/math-physics-83966

    As a personal view I find it annoying to convert even though I found the conversions. It’s often simpler to just not use the physics behavior.

    For instance if you used the bullet behavior instead you could set the acceleration to -200 and set the initial velocity to sqrt(-2*dist*-200) and get the same result.

  • rojohound

    thanks for your answer!

    When i get you right, my function would look like that (apply impulse):

    (Self.Physics.Mass * sqrt(-2*LayoutWidth*((Strenght_Mask.Width/Strenght.Width) * -100) / Self.Physics.Mass)) * 0.02

    (i negate the force value ((Strenght_Mask.Width/Strenght.Width) * -100), because you had a negative force in your excample.)

    Iam not sure for the variable f, because you set it to a fix value (-200). That value is the dynamic variable, my force has to be calculated from - i guess. So in my case its a value between 0 and 100 (ill get it from the strength_mask.width/strength.width calculation)

    The global number dist = LayoutWidth (20000 in this case, but it should be dynamic, if i change it to 30000 or X)

    The function to slow down (apply force):

    ((Strenght_Mask.Width/Strenght.Width) * -100)

    But this doesnt work as supposed. (i guess i did something wrong)

    To clarify:

    when my force is = 100, the objects should slide to position LayoutWidth(20000)

    when my force is = 50 , the objects should slide to position LayoutWidth(10000)

    when my force is = 25 , the objects should slide to position LayoutWidth(5000)

    so it should be relatvie to this value. Currently the objects slides to the same value, it doesnt matter which force i have.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry for the late reply. I can’t say what’s amiss. I have the bad habit lately of not verifying my ideas work correctly. I just haven’t had time to test or debug anything.

    I don’t think I’m much help very often on here anymore. The issue could be with how the conversions are applied, or maybe the conversions are off, or could be the top of my head math and logic are flawed. I’ve buried myself to solve all that and I’m not able to work though it at this time.

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