I have On
void OnTriggerStay()
But it only does the function once then stops, I need it to run constantly for this to work correctly
void OnTriggerStay()
{
rightDoor.eulerAngles = Vector3.Slerp(currentAngle, new Vector3( 0, 90, 0), Time.deltaTime * speed);
leftDoor.localEulerAngles = Vector3.Slerp(currentAngle, new Vector3( 0, -90, 0), Time.deltaTime * speed);
}
Why is OnTriggerStay only running once? it moves 1 frame then stop
I suspect OnTriggerStay is getting called correctly, every frame in which an object is within the trigger; the problem is with your use of Slerp.
What your code says currently is, in each frame, “Set the angle of the door to be t fraction of the way from currentAngle to some other angle.” Where t is Time.deltaTime * speed. There’s nothing in that statement that suggests that the door should continuously open or close - it’s just set to a fairly arbitrary position.
Perhaps you meant:
void OnTriggerStay()
{
rightDoor.eulerAngles = Vector3.Slerp(rightDoor.eulerAngles, new Vector3( 0, 90, 0), Time.deltaTime * speed);
leftDoor.localEulerAngles = Vector3.Slerp(leftDoor.localEulerAngles, new Vector3( 0, -90, 0), Time.deltaTime * speed);
}
?