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 convictcartel · Feb 20, 2014 at 04:44 AM · rigidbodyfloatflyglide

Parachute/Glide

For my FPS I need a parachute or glide script but I cant get it to work..

I tried using a courotine because I couldnt detect when I was falling, so if I jumped up the parachute would still be able to be used.

 if(Input.GetKey (KeyCode.P)) {
         if (parachutefall==true) {
         gravity = 1;
         flying = true;
         inAirControl = 0.0001;
         } else if(gravity==1) {
             gravity = 25;
             rigidbody.drag = 0;
     flying = false;
         inAirControl = 0.01;
         }
     } 
     
     
     if (grounded == true) {
     gravity = 25;
     flying = false;
         inAirControl = 0.01;
         parachutefall = false;
     }
 
 
 if (grounded == false) {
   StartCoroutine(WaitAndPrint(2.0)); 
 }
 
 function OnGUI(){
     if(onLadder && !canClimb)
     GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/2 - 170),800,100),"Press key >>E<< to Climb");
     
         if (flying == true) 
     GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/2 - 170),800,100),"Press >>P<< to Cut Loose");
 
 //if (parachutefall == true) 
     //GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/2 - 170),800,100),"Press >>P<< to Use Parachute");
 
 }
 
 function WaitAndPrint (waitTime : float) {
 yield WaitForSeconds (1);
 parachutefall = true;
 }

 
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
0

Answer by MattMorris · Feb 20, 2014 at 05:23 AM

What I would do is have all your falling logic be placed in a different script or function IE:

 function ParachuteLogic()
 {
     if(parachuteIsOpen) //this is short hand for parachute == true
     {
 
     }
 
 }

Then within your update keep checking for that P button press so:

 function Update()
 {
     if(Input.GetKey(KeyCode.P))
     {
         parachuteIsOpen = true; 
     }
 }

This helps keep things seperated and extendable. Its now easier to add your jump into the mix to detect for that. So now we will update our update function.

 function Update()
 {
     if(Input.GetKey(KeyCode.P))
     {
         parachuteIsOpen = true; 
     }
 
     if(Input.GetKey(KeyCode.Space))
     {
         playerIsJumping = true; 
     }
 }

We can now take our same though process as keeping things compartimentalized and seperate and use that for our player jump. So in a new function we can do something like this:

 function Player()
 {
     if(playerIsJumping)
     {
         var timeSinceJump : int += Time.deltaTime; // you could us this as your timmer
     }
 }

You also said you didn't want to allow the user to activate the parachute if the user jumped so you can now simple do this in that update function:

 function Update()
 {
     if(Input.GetKey(KeyCode.P))
     {
         if(!playerIsJumping) // this is shorthand for playerIsJumping == false
         {
             parachuteIsOpen = true; 
         }
     }
 
     if(Input.GetKey(KeyCode.Space)) // space is a common jump button in games, but this can be remapped. 
     {
         playerIsJumping = true; 
     }
 
     Player(); // make sure anything that uses time is  included in your update function
 }

I think the majority of your problem is not viewing things as individual steps and breaking it down into those steps. Not sure exactly what your problem was, but I hope this answered your parachute opening while jumping problem. Let me know if you have any more questions or need anymore help!

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 convictcartel · Feb 20, 2014 at 06:21 AM 0
Share

i tried to implement this in a new script i couldnt get it to work..

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

19 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

Related Questions

How to make sure that my cube can only jump when in contact with the ground 2 Answers

I do not want to fly a car 0 Answers

Trying to create glide effect 1 Answer

Problems making a glider 3 Answers

Is there a way to smoothly transition between two floats, with it slowing down towards the end 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