Hey everyone…
I’m trying to figure out how to get an object to block a door. Nothing I try seems to work consistently.
In the pics I attached you can see i just have a block that in the first pic the doors just completely pass through. The second one they manage to stop. It seems the only way the door stops is if the object is moving when the doors closed. If the block is stationary it’s like it doesn’t see them.
So I have two identical scripts on each door right now:
void OnCollisionStay(Collision collision) {
Rigidbody rigidbody;
if((rigidbody = collision.gameObject.rigidbody) != null) {
//Debug.Log (collision);
hasCollision = true;
}
}
void OnCollisionExit(Collision collision) {
hasCollision = false;
}
and then on the parent object of the door I have this:
if(leftDoorBlockScript.isColliding() == false rightDoorBlockScript.isColliding() == false) {
float percent = (((Time.time - startTime) * speed) / openDistance);
if(percent > 1) animating = false;
leftDoor.transform.localPosition = Vector3.Lerp (leftDoorOpenPosition, leftDoorClosePosition, percent);
rightDoor.transform.localPosition = Vector3.Lerp (rightDoorOpenPosition, rightDoorClosePosition, percent);
When it does work, it works exactly how I want it to… it stops when a rigidbody is obstructing the door frame and when the object is moved it continues to close until it reaches its “closed” point. The way it’s acting though is that it doesn’t even see the collision. I tried slowing the doors down to see if it was the speed they were closing at and that didn’t seem to affect anything.
Any ideas?