advanced math?

Get help using Construct 2

Post » Mon Dec 15, 2014 1:11 am

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
Posts: 563
Reputation: 5,141

Post » Mon Dec 15, 2014 2:04 am

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.
Posts: 1,973
Reputation: 9,841

Post » Tue Dec 16, 2014 12:17 am

Search for "kinematics projectile motion" in Google.
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
Posts: 1,414
Reputation: 4,822

Post » Tue Dec 16, 2014 2:05 am

not sure if this will help or not: ... cing-games
Posts: 72
Reputation: 721

Post » Tue Dec 16, 2014 7:36 am

You'll mainly be interested with the stopping distance which can be derived from this kinematic equation:
vf^2 = v0^2 - 2*a*d
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:
Code: Select all
if( speed < max_speed) then accelerate

if( distance_to_target <= -(speed^2)/(2*deceleration) then decelerate
Posts: 5,235
Reputation: 67,756

Return to How do I....?

Who is online

Users browsing this forum: ketramtu18, MaujDeveloper and 8 guests