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 /
This question was closed Dec 06, 2016 at 01:55 AM by Drake2312 for the following reason:

solution found by using an external loop to be the counter for length of time that you can glide and increase the number of flaps

avatar image
0
Question by Drake2312 · Nov 25, 2016 at 11:31 PM · timeaddflying

adding time to int

hi i am trying to make a semi-realistic bird flight code, but i am having an issue where when i try to add an int value of the time to the available wing flaps after the first initial period it instantly increases by each part of a second instead of the 2 seconds it should be, simpler it is meant to add 1 to flaps for every 2 seconds you are gliding instead after the first 2 seconds it just increases almost instantly. Here is the code. if this can be done easier using javascript please say so and give an example, still learning c# and haven't started with javascript, i have prior knowledge of software coding from software development classes, but that was using visual basic.

 private Rigidbody rb;
     public Text glidetime;
     public Text flapnum;
     public Text StateCheck;
     public bool grounded = true;
     public float timePressed = 0f;
     public float currentTime;
     public float rest;
     private int flaps;
     private int flaps2;
     private int flaps3;
     
     void Start()
     {
         rb = GetComponent<Rigidbody>();
         flaps = 10;
         setflaptext();
         setglidetext();
     }
 
     
     void Update()
     {
         glideTimer();
         glide();
         fly();
         flaps3 = flaps;
         if (!grounded && rb.velocity.y == 0)
         {
             grounded = true;
             StateCheck.text = rb.velocity.y.ToString();
         }
 
         if (Input.GetButtonDown("Jump") && grounded == true)
         {
 
             rb.velocity += new Vector3(0.0f, 20.0f, 0.0f);
             grounded = false;
             StateCheck.text = rb.velocity.y.ToString();
         }
         //if (Input.GetButton("Fire1"))
         //{
         //    flaps = 
         //}
     }
 
     void FixedUpdate()
     {
 
     }
 
     // glidetimer is used to check the length of the time gliding and increase the number of flaps by a set variable
     void glideTimer()
     {
         if (grounded == false)
         {
             if (Input.GetButton("Fire1") && timePressed < 10)
             {
                 timePressed += Time.deltaTime;
                 currentTime = timePressed;
                 rest = (int)currentTime;
                 flaps = flaps3 + (int)currentTime / 2;
                 setglidetext();
                 setflaptext();
             }
         }
      }
 
     // glide is the physics of the glide control
     void glide()
     {
         if (Input.GetButton("Fire1") && grounded == false)
         {
             rb.drag = 15;
         }
         if (Input.GetButtonUp("Fire1"))
         {
             rb.drag = 0;
         }
     }
 
     void fly()
     {
         if (flaps > 0)
         {
             if (Input.GetButtonDown("Jump") && grounded == false)
             {
                 rb.velocity += new Vector3(0.0f, 10.0f, 0.0f);
                 flaps = flaps - 1;
                 flaps2 = flaps;
                 timePressed = 0;
                 currentTime = 0;
                 setflaptext();
                 setglidetext();
             }
             else if (flaps > 10)
             {
                 flaps = 10;
             }
         }
     }
 
     void setflaptext()
     {
         flapnum.text = "Flaps: " + flaps.ToString();
     }
 
     void setglidetext()
     {
         glidetime.text = "Glide time: " + currentTime.ToString();
     }
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

77 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

Related Questions

How can I compare transform.position now and transform.position after 2 seconds? 2 Answers

few buttondown in fixed time 1 Answer

Suspension of Physics 1 Answer

Get position of object that uses Perlin Noise X distance/time back/offset? 0 Answers

Change scene after event (time or clicking on object) 0 Answers


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