using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorTrigger : MonoBehaviour
{
public GameObject door;
public GameObject openDoor;
public GameObject closeDoor;
Vector3 NewPos;
Vector3 EndPos;
void OnTriggerStay(Collider col)
{
NewPos = openDoor.transform.position;
EndPos = closeDoor.transform.position;
door.transform.position = Vector3.Lerp(door.transform.position, NewPos, Time.deltaTime);
}
void OnTriggerExit(Collider col)
{
NewPos = openDoor.transform.position;
EndPos = closeDoor.transform.position;
door.transform.position = Vector3.Lerp(door.transform.position, EndPos, Time.deltaTime);
}
}
I have this code, but the second Lerp only moves the object once in one frame and depending on the time it moves into position in one movement not smoothly, or just moves a fraction and doesn’t reach it’s target/ how do I fix this