How can I detect whether the player has landed vertically in a downward direction on switch?
Note: I am attempting this within OnCollisionEnter, switch has a box collider
How can I detect whether the player has landed vertically in a downward direction on switch?
Note: I am attempting this within OnCollisionEnter, switch has a box collider
I believe that I may have found my answer (with thanks to Detect Collision From Bottom? - Questions & Answers - Unity Discussions):
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "Player") {
// Is player direction downward?
if (Vector3.Dot(collision.contacts[0].normal, -Vector3.up) > 0.5f) {
// Do cool stuff!
}
}
}
Given that the collision is between the player and the switch is it likely that there will be more than one contact point?
there could and probably will be several contact points. As you see collision.contacts[] is an array, the index being the order of contact. for ex, if the left foot touches the ground and then the right foot, contacts[0] will return the info between the left foot and the ground. But they will probably return pretty similar info.
– fafase