1
\$\begingroup\$

I have a moving platform which is being moved like this:

Vector2 currentPosition = rigidBody2d.position;
Vector2 movement = Vector2.MoveTowards(currentPosition, target, speed * Time.deltaTime);
rigidBody2d.MovePosition(movement);
velocity = (movement - currentPosition) / Time.deltaTime;

And I want to have the moving platform ease in and out of target speed when moving. Basically accelerate from starting position up to speed defined in speed parameter and then decelerate when near target position.

Someone told me to try using SmoothDamp instead of MoveTowards but I am a little perplexed with the behavior.

I've tried using it as follows:

Vector2 movement = Vector2.SmoothDamp(currentPosition, target, ref velocity, 0.1f, speed);

but no matter how much I modify the smoothTime the platform never goes near the set speed (5). It is mostly below 1 or around 1-1.1

What am I doing wrong here? How can I implement easing for my moving platform while still having it reach the set speed?

\$\endgroup\$
1
  • \$\begingroup\$ SmoothDamp isnt designed to move something at a set speed, its meant to dampen it. What you are asking is just setting the velocity basically. If you still want some sort of easing then perhaps just use Lerp() or something? \$\endgroup\$
    – Pow
    Commented Feb 28 at 9:39

1 Answer 1

0
\$\begingroup\$

The speed parameter you are passing to the function is the maximum speed that SmoothDamp will give you, not the desired speed or such. It seems as if your distance is too short, such that it can be covered in the specified time (0.1 sec) without reaching the maxSpeed. You can indirectly adjust the speed by using a lower smoothTime. Note that you will probably not be able to reach exactly an actual speed of 5.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .