Question by
Thirsty-Robot · Apr 21, 2018 at 12:52 AM ·
cameramovementbugsmooth
Help with smooth camera movement
Hi, I've been coding a script for my camera. This is supposed to make the camera move smooth as silk, but I'm having trouble with it. Every time the game starts, the camera does a massive zoom on my character, and freezes, but in the Scene screen, moves just fine. Do you have any idea of this bug?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour {
public GameObject follow;
public Vector3 targetPos;
public float moveSpeed = 6f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
targetPos = new Vector3 (follow.transform.position.x, follow.transform.position.y, follow.transform.position.z);
transform.position = Vector3.Lerp (transform.position, targetPos, moveSpeed * Time.deltaTime);
}
}
Thank you!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612161217im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using Camera.main.ViewportToWorldPoint to limit player movement in the Y direction 0 Answers
How can I smooth out 2D object movement? 0 Answers
SmoothCameraCrouch 2 Answers
How to make an object go the direction it is facing? 0 Answers
Moves itself. 1 Answer