• 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 Pflobus · Jun 24, 2015 at 09:02 PM · rotationrigidbodyfallingontriggerexit

Fall time and Unfreezerotation on a rigidbody.

So in my script, the character falls, and if the character was falling for enough time, when it lands, the freeze rotation on the rigidbody turns off (I wasn't sure about how to do that, so currently it's "Destroy(gameobject)").

 #pragma strict
 
 
 var isfalling : boolean = false;
 
 function Start() {
     var Player = GameObject.Find("Player");
 }
 
 function OnTriggerExit() {    
     if (Input.GetButtonDown("Jump")) {
         var beginJumpTime = Time.time;
     }
     
     var currentAirTime : float = Time.time - beginJumpTime; //The detection of how long the player falls isn't working.
     
     if ((currentAirTime >= 30.0F))//This is supposed to measure time (time of the player's fall), but it doesn't stop after being activated, so it keeps measuring.
      {
          isfalling = true;
          Debug.Log(currentAirTime);
      }         
      else {
          isfalling = false;
      }    
 }
 
 function OnTriggerEnter() {    
     if (isfalling) {
         Destroy(GameObject.Find("Player"));//I want this to actally have it turn off the freeze rotation on the collider, and wait for 3 seconds, then turn the freeze rotation back on, as well as re-orient the player.
     }
 }


Any help as to how to unfreeze rotation (on the Rigidbody), and detect the time of a fall would be great. Thank you!

Comment
Add comment · Show 10
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 rhbrr5hrfgdfgw · Jun 24, 2015 at 09:11 PM 0
Share

Can you put debug after this line: var currentAirTime : float = Time.time - beginJumpTime;

Debug.Log(currentAirTime);

avatar image Pflobus · Jun 24, 2015 at 09:19 PM 0
Share

Yeah...not getting an error from that. Just that it doesn't work as intended.

avatar image rhbrr5hrfgdfgw · Jun 24, 2015 at 09:22 PM 0
Share

I mean can you add a debug after this line and tell me what is the output

avatar image Pflobus · Jun 24, 2015 at 09:24 PM 0
Share

Oh...it displayed the time, but what happened was it waited for 30 seconds, and then when I pressed jump after that, it would finally display the time. So it wouldn't stop ti$$anonymous$$g even after I stopped falling.

avatar image Pflobus · Jun 24, 2015 at 09:28 PM 0
Share

The output was 38.06 seconds.

avatar image rhbrr5hrfgdfgw · Jun 24, 2015 at 09:29 PM 0
Share
 var startTimer : boolean = false;
  var currentAirTime : float;
 function Update(){
 if (Input.GetButtonDown("Jump")) {
      startTimer = true;
  }
  if(startTimer) currentAirTime += Time.deltaTime*1;
  
  if (currentAirTime >= 30)
   {
   //Its been 30 seconds what you want to do now?
   }
  }
avatar image Pflobus · Jun 24, 2015 at 09:37 PM 0
Share

That doesn't work. What I want is once the player leaves the trigger, they fall. If they are falling for 30 seconds, when they land, then unfreeze rotation on all axises for the Rigidbody.

avatar image rhbrr5hrfgdfgw · Jun 24, 2015 at 09:39 PM 1
Share

Just one more question and i will help you build the script, what trigger?

avatar image Pflobus · Jun 24, 2015 at 09:40 PM 0
Share

Thanks! It is at the bottom of the player. That way it detects if the player jumps, so it can start counting, as well as when the player lands, so that it will deter$$anonymous$$e if the player made the jump or not.

avatar image Pflobus · Jun 24, 2015 at 09:54 PM 0
Share

@maccabbe Thanks!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by rhbrr5hrfgdfgw · Jun 24, 2015 at 09:54 PM

                      var startTimer : boolean = false;
                       var currentAirTime : float;
                 var mark30Sec : boolean = false;
                      function Update(){
                      if (Input.GetButtonDown("Jump")) {
                           startTimer = true;
                       }
                       if(startTimer) currentAirTime += Time.deltaTime*1;
                       
                       if (currentAirTime >= 30)
                        {
                        mark30Sec = true;
                        }
                       }
                     
                     function OnTriggerEnter() {
 TriggerFunction();
 }
     
     function TriggerFunction(){
                 currentAirTime = 0;
                 startTimer = false;
                      if (mark30Sec)
             rigidbody.constraints =  RigidbodyConstraints.None;
     yield WaitForSeconds(3);
     Application.LoadLevel("PUT YOUR LEVEL NAME HERE AS STRING");
                     }

So when the player touches something (using the OnTrigger) and it has been in air for 30 second then freeze all rotations.(And when ever the player touches something reset the timer back to zero for next jump. Since you can call yield WaitForSecond on the function: OnTriggerEnter() then you need to call it from other function.Now every thing should work.

Comment
Add comment · Show 11 · 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 Pflobus · Jun 24, 2015 at 10:00 PM 0
Share

Thanks! That works really well. Only problem is that the rigidbody's freezerotation doesn't turn off, and the timer doesn't reset?

avatar image rhbrr5hrfgdfgw · Jun 24, 2015 at 10:03 PM 0
Share

What do you mean doesn't turn off? in what situation you want it to turn off? and i edited the code, i forgot to set the startTimer = false; after the collision.

avatar image Pflobus · Jun 24, 2015 at 10:08 PM 0
Share

So like the Unfreeze rotation, after trigger enter, should have everything unchecked. And how do you make its so that even you didn't press jump, but you are still falling, the timer runs?

avatar image rhbrr5hrfgdfgw · Jun 24, 2015 at 10:18 PM 0
Share

Now every thing should work, first i thought you wanted to FREEZE rotation..

avatar image Pflobus · Jun 24, 2015 at 10:26 PM 0
Share

One last thing...this script only works if you jump. I want the timer to count once the player starts falling.

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Engine weight Simulation 2 Answers

Rotating sphere with rigidbody attached 1 Answer

How can I rotate and move a cylindrical rod from one side with respect to other side? 1 Answer

why can't my Rigidbody not rotate on slopes? 1 Answer

Limit Rotation of Rigidbody to 45 Degrees (Handlebars on a Bicycle) 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