Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Toy · Feb 17, 2012 at 02:17 AM · detectioncounterfall

Death fall

Im a designer student and I am making a game which involves a player that dies when he falls from more than 10 meters. I have a lot of platform in my map from different height. I want to know how can I make a script that recognizes that my player dies when he falls more than 10 meters.

How can i make a counter that calculates my fall every frame, every time my player fall?

Thank you

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by asafsitner · Feb 17, 2012 at 09:09 AM

Something like this should work, I believe:

 if(!player.isGrounded)
 {
     //calculate the distance between our current height and the height we were in the last frame
     lastYTravelDistance = player.position.y - lastYPosition;
 
     //if the difference is negative, it means we're descending 
     fallHeight += lastYTravelDistance < 0 ? lastYTravelDistance : 0;
 }
 else
 {
     //we check to see if we passed the allowed falling distance and kill the player if necessary
     if(fallHeight >= -deathHeight)
         KillPlayer();
     
     //reset fall height since we landed (doesn't matter if we're dead or alive)
     fallHeight = 0;
 }
 
 //cache our current Y position for comparison in the next frame
 lastYPosition = player.position.y;
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shadowpuppet · Jul 30, 2016 at 07:29 PM 0
Share

yeah, that might work but a little more info would help. Like is this JS or C#? void start? function start? function update void update, what var need to be at the start

avatar image nikm902 · Mar 16, 2017 at 02:46 PM 0
Share

Thank you so much. It's very simple solution with only one correction, as I think. There is need sign lower at line if (fallHeight <= -deathHeight) So after that it works just fine.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error in Raycast Detect Ground for Falling Animation 1 Answer

Particle Collision / Trigger not being reported to On_xx Event 1 Answer

Unity Auto detecting... 2 Answers

Edge crossing detection 1 Answer

Collision Checking 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges