Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 943 Bytes

README.md

File metadata and controls

27 lines (23 loc) · 943 Bytes

Smooth Follow with Lerp for Unity

private void Update()
{
    speed = sliderSpeed.value;
    follower.transform.position = Vector3.Lerp(follower.transform.position, transform.position + followerOffset, speed);
    if (lookAt.isOn) follower.transform.LookAt(transform.position);
}

private void OnMouseDown()
{
    screenPoint = Camera.main.WorldToScreenPoint(transform.position);
    offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}

private void OnMouseDrag()
{
    Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
    Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
    transform.position = curPosition;
}