- Home /
Detect when falling
Hello I'm just trying to detect when my character is falling at a rapid rate maybe from a high place. I tried searching it up but the forums/threads I read were to check if the character was grounded or not for jumping. I'm trying to detect when I player has fallen off something high and is falling down rapidly. I was thinking of doing rigidbody.velocity.y <= some value but I'm not sure if falling bodies in unity accelerate/increase speed when falling. Would appreciate some feedback. Thanks!
Answer by Glaas · May 05, 2020 at 01:20 PM
Hi ! I just did some quick tests and this is what I'm suggesting.
First, you want to create variables in your script that will reference the rigidbody of your character and the value of its velocity.
You want to store the value of your character's velocity in a variable, and maybe make it public so you can check it from the inspector.
Here's what the code would look like :
If you want to check if the value goes above a specific treshold, simply add an if statement like this ;
Hope it solves your question !
Sorry for the late reply but when you're falling wouldn't the value be negative and not positive? Sorry I'm not quite sure.
yes, it would be negative. try comparing to -50
Yes it would ! Try comparing it to -50 for instance, or convert your variable, there's tons of ways to approach this situation ! :)
Hope I helped you, don't forget to mark your question as resolved and upvote me if that's the case !