Hi all,
I’ve been trying for a while now to get this to work. I’m not entirely sure where I went wrong, but here is the script I’ve made:
public Vector3 offset;
public float smoothing;
int number;
void Start()
{
number = 0;
}
void Update ()
{
if(Input.GetKeyDown(KeyCode.E))
{
DoorSlide();
}
}
void DoorSlide()
{
if (number == 0)
{
transform.position = Vector3.Lerp(transform.position, transform.position + offset, Time.deltaTime * smoothing);
number++;
}
else
{
transform.position = Vector3.Lerp(transform.position, transform.position - offset, Time.deltaTime * smoothing);
number--;
}
}
I’m setting it up so I can open and close the door by pressing E. I’d like the door to “slide” from it’s current position (either open or closed) to its other position.
The difficulty I’m having is that the door opens and closes with the above script, but it snaps from its initial position to its final position. There is no lerping happening.
Any and all suggestions are welcome, and thank you in advance for your time!