Hi guys, I am trying to limit my character’s movement to a constrained area with a trigger, but it’s not quite working. It almost works, but My character controller breaks free at certain angles… Does anyone know how to fix this?
Source Code:
`
private Vector3 lastPosition;
void OnTriggerStay (Collider other)
{
//This records the last position the object was fully INSIDE the trigger
lastPosition = other.transform.position;
}
void OnTriggerExit (Collider other)
{
//This resets the character's position to last positition fully inside the trigger if they try to exit
other.GetComponent<Transform>().position = lastPosition;
}`