1
\$\begingroup\$

Currently I am only using deceleration.

Here is how I do it

I need to cover Vector(x,y) unit distance to reach B from A.

I simply do -

rendering loop->

  1. position = A + Vector(x,y).scale(factor);
  2. Vector(x,y) = Vector(x,y) - Vector(x,y).scale(factor);

...factor = 10 for example So if I have to cover 100 units, I cover 10 then 9 then 8.1 and so on in every frame.

How do I simulate acceleration then deceleration here?

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Acceleration changes velocity in the same way velocity changes position. So, change your velocity over time to simulate acceleration. (BTW, "deceleration" isn't really a separate thing, it's just a short way of saying "acceleration in the direction opposite of travel") \$\endgroup\$ Commented Jul 31, 2013 at 16:39
  • \$\begingroup\$ Your have basically simulated drag coefficients, although you'd genereLly have a different "factor" for drag vs whatever your doing with position there, which some people struggle quite a bit with, so good job there. \$\endgroup\$ Commented Jul 31, 2013 at 22:18

1 Answer 1

3
\$\begingroup\$

A simple way is to animate the object using a smoothstep curve:

lerpFactor = (curTime - startTime) / timeToReachTarget; smoothstepFactor = lerpFactor * lerpFactor * (3.0 - 2.0 * lerpFactor); position = lerp(startPos, targetPos, smoothstepFactor); 

Here, I'm assuming a specified amount of time to reach the target (timeToReachTarget) and calculating how far the object should have moved by the current time (lerpFactor), then passing it through the smoothstep curve to make it accelerate and decelerate smoothly.

This isn't an especially physics-based approach, nor does it work well if the target point is moving, but it does create a smooth-looking motion.

\$\endgroup\$
2
  • \$\begingroup\$ lerpFactor * lerpFactor * (3.0 - 2.0 * lerpFactor) is not the same that 3x^2 -2x^3, is there an error ? \$\endgroup\$ Commented Mar 24, 2014 at 22:52
  • 2
    \$\begingroup\$ @kosokund They're the same; I just wrote it in a factored form that avoids redundant calculations. It's a common trick for polynomials. \$\endgroup\$ Commented Mar 25, 2014 at 1:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.