- Home /
Question by
yoyo8825 · Mar 04, 2014 at 01:41 AM ·
smoothdampsmooth follow
non physics GO slowly stop when near target location.
I have a GameObject with smoothfollow script attached to it. My goal is that when this GO is close to the target(such as within 10 meters range), it would smoothly slow down to stop, without actually reaching the pivot point of target. I have tried to setup different bool and conditions, but result in jagging movement. so how will you do it? on a side note what does the "velocity" inside Mathf.SmoothDamp do?
public float smoothTime;
public GameObject target
private Vector3 velocity;
void Start ()
{
smoothTime = 0.3f;
}
void Update ()
{
transform.position = new Vector3(Mathf.SmoothDamp(transform.position.x, target.transform.position.x, ref velocity.x, smoothTime),
transform.position.y,
Mathf.SmoothDamp(transform.position.z, target.transform.position.z, ref velocity.z, smoothTime));
}
Comment
Your answer
Follow this Question
Related Questions
Changing Targets - Smooth Damping X and Z on SmoothFollowCamera 0 Answers
why target switching of smooth camera not very smooth ? 0 Answers
Does SmoothDamp reach target? 2 Answers
Smooth Follow 2D works but Null Reference Error Remains 1 Answer
Why is my SmoothDamp taking four times longer to finish than it should? 1 Answer