advanced math?

0 favourites
  • 5 posts
From the Asset Store
An advanced inventory example similar to Terraria.
  • Okay everyone. The answer to this might be easy or not...

    Given an object with the following variables:

    Velocity X

    Max Speed

    Rate of acceleration and deceleration

    Distance to target

    How do I know when to decelerate to arrive at the target and have 0 velocity when I do. Basically I have an object that needs to accelerate towards a target and then begin decelerating at the right time.

    I Was looking around and found some physics equations that give me things like distance = Acceleration * time ^2 but that doesn't help much... position = position + velocity is how velocity integration works in most games and that gives a different number than physics equations (euler explicit integration???) I don't know what I am talking about but all I know is I spent 3 hour trying to figure out how to calculate when to slow down with no luck and google didn't help

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • it's dependent on your rate of deceleration, current speed, and distance to target.

    you haven't given enough information as to how exactly you want this to work, is the deceleration something that can change with time? that makes things much more complicated, and would necessitate some kind of PID loop to make an estimation of how to alter the velocity. If your deceleration is constant its simple algebra.

    for the pid loop you'd have to alter velocity based on the current speed and distance to target and some value to control sensitivity. You'd need to carefully tune things not to overshoot. If you know deceleration will be constant for the entirety of the stopping motion you just need to solve using an appropriate kinematic equation, depending on how far you want to move before stopping / what constant rate you wish to decelerate. in each of these cases you'd need to do different things. If you had a specified stopping rate you'd need to find at what distance to begin decelerating. if you wanted to stop at a particular point from any distance to target you'd need to solve at that instant what constant rate to decelerate at until velocity is zero and the target has been reached.

  • Search for "kinematics projectile motion" in Google.

  • not sure if this will help or not:

    https://www.scirra.com/tutorials/1051/b ... cing-games

  • You'll mainly be interested with the stopping distance which can be derived from this kinematic equation:

    vf^2 = v0^2 - 2*a*d

    where

    vf is the final velocity

    v0 is the initial velocity

    a is the acceleration

    d is the distance

    We want to know how far it takes to stop with a given speed and deceleration. So:

    speed^2 = 0^2 - 2*deceleration*distance

    solving for distance we get:

    distance = -(speed^2)/(2*deceleration)

    Note: if the value you use for deceleration isn't negative you can omit the minus in the formula.

    So then our pseudo code to move the object would be:

    if( speed < max_speed) then accelerate
    
    if( distance_to_target <= -(speed^2)/(2*deceleration) then decelerate[/code:bepp4si0]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)