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 Major · Mar 01, 2013 at 02:28 AM · rigidbodyspeeddamagefally axis

Fall Damage

What is the best way to find fall damage? I have an idea that I wrote, but I'm not sure if it's the best way. Any guidance?

 var v = rigidbody.velocity.y;
     var d = 1;
     speed = v;
     
     if(grounded == true)
     {
         speed = 0;
         
         if(v < -1.0)
         {
             health += v;
         }
     }
Comment
Add comment · Show 1
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 sacredgeometry · Aug 11, 2019 at 08:04 PM 0
Share

Whats d for?

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by sacredgeometry · Aug 11, 2019 at 08:38 PM

Something like this? It works in all directions but you could easily reduce it just to the Y axis.

     public Vector3 Velocity;
     public Rigidbody RidgedBody;
     public bool IsAlive = true;
     private double _decelerationTolerance = 12.0;
 
     void Start() 
     {
         RidgedBody = GetComponent<Rigidbody>();
     }
     void FixedUpdate() 
     {
         if(IsAlive)
         {
             IsAlive = Vector3.Distance(RidgedBody.velocity, Velocity) < _decelerationTolerance;
             Velocity = RidgedBody.velocity;
         }
     }
Comment
Add comment · Show 5 · 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 Major · Aug 11, 2019 at 08:53 PM 1
Share

Because you answered my silly question for 6 years ago (I have no idea why) I will reward you with some internet karma XD

avatar image sacredgeometry Major · Aug 11, 2019 at 09:00 PM 0
Share

Haha no way! I cant even remember what that was.

avatar image sacredgeometry · Aug 11, 2019 at 08:54 PM 0
Share

Note that Vector3.Distance(RidgedBody.velocity, Velocity) gives you the magnitude of the deceleration so you can also use it to deter$$anonymous$$e how much damage to deal.

avatar image Major sacredgeometry · Aug 11, 2019 at 08:59 PM 1
Share

I would just use the magnitude member function in Vector3 class. Using the distance method does exactly the same thing, but is less concise.

avatar image ramkhilnani · Nov 09, 2020 at 11:27 AM 0
Share

I tried adding this to my code but it doesn't seem to work. Could you please explain which part triggers the fall damage?

avatar image
2

Answer by hristo991 · Jul 07, 2014 at 07:31 PM

For character controller I would use a variable that calculates the air time and then take from the player's health when touching the ground:

 var minSurviveFall : float = 2f; //the time that the player can spend in the air without taking damage
 var damageForSeconds : float = 1f; //damage taken for 1 second in air (for airTime = 1)
 private var _controller : CharacterController;
 private var airTime : float = 0;
 
 var playerHealth : float = 10; //you can use your own variable here, or make a reference to a variable in other script
 
 function Start () {
 _controller = GetComponent(CharacterController);
 }
 
 function Update() {
 if(!_controller .isGrounded)
 {
 airTime += Time.deltaTime;
 }
 if(_controller .isGrounded)
 {
 if(airTime > minSurviveFall)
 {
 playerHealth -= damageForSeconds * airTime;
 }
 airTime = 0;
 }
 }

It is checked for errors, but it's not playtested

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 Super_Solomob422 · Aug 11, 2019 at 07:58 PM 1
Share

Velocity is more realistic and compatible, if you have a flying mechanic it makes more sense to use velocity, other wise you would get hurt for hovering right above the ground for a while.

avatar image
1

Answer by NateLaw1988 · Aug 19, 2019 at 01:45 PM

Hi I know this is an old post but incase someone new comes along like I did I have posted a video with a project download link to a heavily extended first person controller

https://www.youtube.com/watch?v=NLe9QOw05kM&t=13s

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

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

15 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

Related Questions

Make object fall with constant speed! 4 Answers

Kinematic how to know rigidbody velocity vector? 1 Answer

How do I make my character's speed stay consistent? 0 Answers

Pushing rigidbodies around 1 Answer

Rigidbody load problem 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