- Home /
Question by
UnresolvedExternal · Jul 20, 2015 at 03:58 PM ·
moving-platform
Decelerate moving platform at targets
Hello! I'm trying to make a moving platform move at a constant speed and then when it is near the target start to slow down, I have trying to do this with Lerp, but I'm not satisfied with the results because of two reasons: it goes way too fast between targets, and way too slow near targets.
Also, when it reaches a target it immediately boosts off in the opposite direction. What I want to achieve is for the platform to move steadily between targets, decelerate near targets, and when reaching a target start to accelerate back to the steady speed.
What is the best way for achieving this? Lerp, Smoothstep, other? Thanks!
My current solution:
_dVeloctiy = _velocity * Time.fixedDeltaTime;
Vector3 newPosition = Vector3.Lerp(_rigidBody.position, currentTargetPosition, _dVeloctiy.magnitude);
_rigidBody.MovePosition(newPosition);
Vector3 dPosition = _rigidBody.position - currentTargetPosition;
if (dPosition.magnitude > 0.05f)
{
_isTurning = false;
}
if (dPosition.magnitude < 0.05f && !_isTurning)
{
currentTargetPosition = (currentTargetPosition == targetPosition1 ? targetPosition2 : targetPosition1);
_isTurning = true;
}
Comment