# move object and slow down near end

I have a spaceship flying in towards a planet (Sphere), rotating and landing. Its working fine, i just want a litle better, im using the Vector3.Slerp and Quaternion.Slerp so that it slows down as it nears the landing spot. But it slows down too mutch, at the end its sooo slow to rotate and land. Any way to make it slow down…slower?

this is the code im using

``````transform.position = Vector3.Slerp (transform.position, landingSpot, flightSpeed * Time.deltaTime / 100);
if (Vector3.Distance (transform.position, landingSpot) < rotateForLandingDistance) {
transform.localRotation = Quaternion.Slerp (transform.rotation, landingRotation, rotationSpeed * Time.deltaTime / 100);
}
``````

Time for a slightly more complex answer then! This is by no means the simplest solution but it is probably one of the most flexible.

By making use of animation curves one can draw a curve (in the editor) to manipulate the speed of an object. Below is a simplified version of a script that does that. If you want to actually use this you will probably want to make changes to script and include a base speed to prevent not moving but this will allow you to achieve the variable speed affect you would like.

I’ll post the script below but you may want to check out these pages for reference:

The actual script:

``````using UnityEngine;
using System.Collections;

public class SlerpTowards : MonoBehaviour
{
public Transform Target;
public AnimationCurve DistanceVersusSpeed;

private float _initialDistanceToTarget;
private float _speed;
private float _distanceToTarget;

public void Start()
{
_initialDistanceToTarget = (Target.position - transform.position).magnitude;
_speed = 0;
}

public void Update()
{
// Calculate our distance from target
Vector3 deltaPosition = Target.position - transform.position;
_distanceToTarget = deltaPosition.magnitude;

// Update our speed based on our distance from the target
_speed = DistanceVersusSpeed.Evaluate((_initialDistanceToTarget - _distanceToTarget) / _initialDistanceToTarget);

// If we need to move father than we can in this update, then limit how much we move
if (_distanceToTarget > _speed)
deltaPosition = deltaPosition.normalized * _speed;

// Set our position
transform.position += deltaPosition * _speed * Time.deltaTime;
}
}
``````