- Home /
Check if player is under or on an object
Hi, i want to make an endless runner game, but i have a problem how can i check if my player is under a terrain part o on it ? Because if the character is under it and i want to jump i have to turn the terrain's collider to trigger but if i am on it or i am falling on it i have to switch it off (trigger)...
Thank you
Answer by LSPressWorks · Jul 20, 2014 at 05:18 PM
var player : GameObject;
FixedUpdate()
{
if (player.transform.y < (obstacle.tranform.y - obstacle.transform.height))
{
player.rigidbody.isKinematic = true;
} else{ player.rigidbody.isKinematic = false ;}
}
Answer by LSPressWorks · Jul 20, 2014 at 05:18 PM
Or you can put an empty object above the players head that takes in the terrain and then in OnCollisionEnter you can set teh object to trigger. A similar trigger on his foot would change the terrain back.
Your answer
Follow this Question
Related Questions
Late Rocket Explosion 1 Answer
Terrain doesn't collide with my mesh 1 Answer
How to create endless terrain... 0 Answers
How do I generate an omnidirectional 2d terrain? 0 Answers
How can I make a trigger detect Terrain? 0 Answers