- Home /
Camera not slowly moving to object
can anyone help me. i need the camera to move slowly to the PosB but what it does is the camera snaps. heres the code
using UnityEngine; using System.Collections;
public class NewCameraScript : MonoBehaviour {
public Transform Target;
public Transform PosB;
public Camera cam;
public float speed;
public float dampTime;
public bool changeView = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D(Collision2D col)
{
if(col.gameObject.tag == "Player")
{
changeView = true;
if(changeView = true)
{
Debug.Log("sadsdahj");
Lerping();
}
}
}
void OnCollisionExit2D(Collision2D col)
{
if(col.gameObject.tag == "Player")
{
changeView = false;
}
}
void Lerping()
{
//float dampp = dampTime * Time.deltaTime;
//cam.transform.localPosition = Vector3.Lerp(Target.position,PosB.position,dampTime);
cam.transform.position = Vector2.Lerp(Target.transform.position,PosB.transform.position,dampTime);
cam.transform.position = new Vector3(transform.position.x+1,Target.transform.position.y - PosB.transform.position.y,-50);
}
}
Comment
Your answer
Follow this Question
Related Questions
Smooth Camera/Object Movement 1 Answer
How to use Lerp? 1 Answer
Move A Camera Between Two Points Smoothly 1 Answer
How you change another script value smoothly on trigger 0 Answers
Modified SmoothFollow 0 Answers