- Home /
OnTriggerStay not updating
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
Answer by tanoshimi · Sep 16, 2014 at 06:20 PM
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);
}
?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Problem with OnTriggerStay2D function 2 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Layermask for OnTriggerStay 2 Answers