- Home /
Check if player is colliding with top face of box collider?
Hi, i need to know how to make my player detect when he's on top of a box collider, so that the game knows when he's allowed to jump. Any ideas? Ive tried separate meshes for the top, but i want an on click function later on, so separate colliders would cause problems...
Answer by Makingames · Mar 22, 2015 at 11:02 PM
You could raycast downwards 1/2 (plus a fractional wiggle room) of the players collider size downwards to see if anythings below it, or maybe if check for a "floor" tag. Most situations you want to check like that and not do anything with the box per se.
Thats good. Thank you! I could also check maybe how high or low my y velocity?
Eh, that would work on flat surfaces, but what about when you're on a hill and moving? Your y velocity will be changing. If you are using a character controller I thiiink it has isGrounded variable that should also do exactly what you want.
Also, if i were to do ray cast, what would happen if the corner of my character's foot was on a block but not the center of his body? In this case it wouldn't work. If i were to do ray cast, how would i fix this issue? @$$anonymous$$akinGames
Your answer
Follow this Question
Related Questions
Collision detection problem 1 Answer
Detecting Collision for Jumping 1 Answer
How to detect a collider in a particle? 4 Answers
Problem with Collider 3 Answers
My Player keeps launching into the air 4 Answers