I have various game objects with a boxColliderTrigger (camTargetCollider) and these check if the player is walking into it. Those gameObjects have different locations and i want to move the camera to the position if the player enters the boxColliderTrigger.
But the camera is not lerping and snaps to the next location without any smoothness.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FixedRoomCamera : MonoBehaviour
{
public Transform Kamera;
public Collider2D camTargetCollider;
public float accum = 0.0f;
public Vector3 p1, p2;
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.tag.Equals("Player"))
{
Debug.Log("Trigger2" + p1 + p2);
p1 = Kamera.position;
p2 = camTargetCollider.bounds.center + new Vector3(0,0,-10);
Kamera.transform.position = Vector3.Lerp(p1,p2, Mathf.SmoothStep(0,1,accum));
}
}
// Update is called once per frame
void Update()
{
accum += 1.1f * Time.deltaTime;
}
void Awake()
{
p1 = new Vector3(0,0,-10);
p2 = new Vector3(0,0,-10);
}
}