- Home /
Simple Camera ZoomIn Out Script
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);
}
}
Comment
Best Answer
Answer by Hellium · Aug 07, 2019 at 09:32 AM
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);
}
}
Your answer
Follow this Question
Related Questions
How can I put a maximum/min range for the Y axis of my freelockcamera ? 0 Answers
Camera Changing size fluidly depending on An Objects y position 0 Answers
Zoom in when player is accelerating/ if not zoom out 0 Answers
How to use vuforia AR Camera for Zoom 1 Answer
How do you change the values of Vector3 Offset (x, y, z) in script randomly/overtime? 0 Answers