Hello Everybody,
This is my smooth camera follow script.I just need add to this script smooth zoom in out.I try some script but not successful.I wait for your helps.
Thanks.
public class CameraSC : MonoBehaviour {
public Transform player;
public float smooth = 0.3f;
public float height;
private Vector3 velocity = Vector3.zero;
private void Update ()
{
Vector3 pos = new Vector3();
pos.x = player.position.x;
pos.z = player.position.z - 7f;
pos.y = player.position.y + height;
transform.position = Vector3.SmoothDamp(transform.position, pos, ref velocity, smooth);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraSC : MonoBehaviour
{
public Transform player;
public float smooth = 0.3f;
public Vector3 offset = new Vector3(0, 4, -7);
public float zoomSpeed;
private Vector3 velocity = Vector3.zero;
private Vector3 position;
private float zoom = 1;
private void Update()
{
zoom -= Input.mouseScrollDelta.y * zoomSpeed;
offset = offset.normalized * zoom;
transform.position = Vector3.SmoothDamp(transform.position, player.position + offset, ref velocity, smooth);
}
}