Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by tupak1993 · Dec 06, 2016 at 05:57 PM · c#movementphysicsposition

how do i make player die when falling certain height?

I want game-over screen to pop up when player falls. my idea is if, player falls certain distance within certain amount of time then set game-over screen active. can anyone show the proper way to write it down please. thanks.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Brylos · Dec 06, 2016 at 07:26 PM

If you're using a Character Controller component it shouldn't be too hard

   public CharacterController Player;
         
   float CurrentFallTime;
   public float MaxFallTime = 3;
   // This is how many seconds you want to occur before it is decided that he will die from falling.
         
   bool PlayerIsFalling;
 
   void Update()
         
         if (Player.isGrounded == false)
         {
         PlayerIsFalling = true;
         }
         else PlayerIsFalling = false;

         if (PlayerIsFalling)
         {
         CurrentFallTime += Time.deltatime;
         }

You didn't specify if you want the player to die when he hits the ground or weather or not he's in the air.

If you want him to be able to die while in the air add this to the update void:

 if (CurrentFallTime >= MaxFallTime)
 {
 PlayerDeath();
 //You'll need to make a void for when your player dies
 }

If you want him to die when he hits the ground add these to the update void:

 if (Player.IsGrounded && CurrentFallTime < MaxFallTime)
 {
 CurrentFallTime = 0;
 }
 
 if (CurrentFallTime >= MaxFallTime && Player.IsGrounded)
 {
 PlayerDeath();
 }

I believe that should work. Tell me how it goes.

Comment
Add comment · 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
0

Answer by tupak1993 · Dec 09, 2016 at 07:50 PM

hi im getting these error....any idea?alt text THanks.


error-1.png (20.7 kB)
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 Brylos · Dec 09, 2016 at 08:35 PM 0
Share

Thats my fault. You'll have to rewrite that section like this:

 if (Player.isGrounded)
 {
 PlayerIsFalling = false;
 }
 else PlayerIsFalling = true;
avatar image tupak1993 Brylos · Dec 10, 2016 at 11:18 PM 0
Share

Thanks appreciate your help but its still not working. there are no compier error but it just doesn't work... any idea? Im beginner on this.

And for some reason i cannot add the scrrenshot either....

avatar image
0

Answer by Coleclaw199 · Dec 11, 2016 at 12:06 AM

public class Fall : Monobehaviour {

 public CharacterController Player;
 
 float CurrentFallTime = 3F;
 
 public bool PlayerIsFalling;
 
 // This is where your error was.
 void Update() // You had a semicolon here.
 {
       if(Player.isGrounded == false)
       {
           PlayerIsFalling = true;
       }
       
       else // Your other error was putting the "PlayerIsFalling = false" here.
       {
              PlayerIsFalling = false
       }
 
       if(PlayerIsFalling)
       {
              CurrentFallTime += Time.daltaTime;
       }
 }

}

This is untested code, so this may or may not fix your problem, good day!

Comment
Add comment · Show 1 · 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 Dovahkiin_4 · Jan 01, 2018 at 01:44 AM 0
Share

every time i try using this code to rester the scene it just says "Scene '1' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded." but it was added to the build settings.

 public class DeathScript : $$anonymous$$onoBehaviour 
 {   
 
     public string Level;
     public CharacterController Player;
     bool PlayerIsFalling;
     float CurrentFallTime;
     public float $$anonymous$$axFallTime = 3;
 
 
     void Update () 
     {
         if (Player.isGrounded == false) 
         {
             PlayerIsFalling = true;
         } else 
         {
             PlayerIsFalling = false;
         }
         if (PlayerIsFalling = true)
         {
             CurrentFallTime += Time.deltaTime; 
         }
         if (CurrentFallTime >= $$anonymous$$axFallTime) 
         {
         Scene$$anonymous$$anager.LoadScene(Level);
         }
     }
 }

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

293 People are following this question.

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

Related Questions

Player Movement Not Always Responding 1 Answer

Make projectile move in certain direction depending on position for base object (C#) 1 Answer

How to know where my object is going to fall? 1 Answer

Enemy attack radius 4 Answers

Draw torus with a spot in the center 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