I've seen similar questions to this here on Stack Exchange — Game Development, but none of the answers to them have helped my problem. I am working in Unity 2019.2.18f1 with Visual Studios 2019 Community.
What I want to know how to tell when one Gameobject (the player) is currently touching another game object with a tag name of "Block". When the player collides with a "block" I want it to set: jumpPossible = true;
But when it leaves the block (by jumping or falling off) jumpPossible = false;
What I currently have in my PlayerController
script (the important stuff anyways):
private void OnCollisionEnter(Collision collision) {
if (collision.gameObject.CompareTag("Block")) {
jumpPossible = true;
}
}
private void OnCollisionExit(Collision collision) {
if (collision.gameObject.CompareTag("Block")) {
jumpPossible = false;
}
}
The problem I am having is when the player is currently on a block and then touches another block. When it leaves the one of the blocks, it will set: jumpPossible = false;
and so you can't jump.
What I want for this script to do is whenever the player is touching any Gameobject with a tag of "Block" it should allow it to jump.
GetContacts
, but unfortunately the 3d Rigidbody seems to miss that feature. \$\endgroup\$OnCollision*()
methods \$\endgroup\$