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 /
avatar image
0
Question by Reissu_Mies · Nov 07, 2018 at 02:41 PM · movementmovement script

Infinite jump still happening,Infinite jump still happening

this should work right?

 public Rigidbody rb;
     
     private bool isGrounded = false;
 
   
     void FixedUpdate () {
         if (isGrounded == true && Input.GetKeyDown(KeyCode.Space))
         {
             rb.AddForce(0, 10000 * Time.deltaTime, 0);
         }
 
     }
     void OnCollisionEnter(Collision other)
     {
         if (other.gameObject.name == "ground")
         {
             if (isGrounded == false)
             {
                 isGrounded = true;
             }
         }
     }
 }
 

,why isnt this working?

 public Rigidbody rb;
     
     private bool isGrounded = false;
 
   
     void FixedUpdate () {
         if (isGrounded == true && Input.GetKeyDown(KeyCode.Space))
         {
             rb.AddForce(0, 10000 * Time.deltaTime, 0);
         }
 
     }
     void OnCollisionEnter(Collision other)
     {
         if (other.gameObject.name == "ground")
         {
             if (isGrounded == false)
             {
                 isGrounded = true;
             }
         }
     }
 }
 
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 Reissu_Mies · Nov 08, 2018 at 03:05 PM 0
Share

So this finally worked (the Debug.Logs are just to see if it worked correctly)

 public class Jump : $$anonymous$$onoBehaviour
 {
     public float jumpForce = 10000f;
     public Rigidbody rb;
 
     private bool isGrounded = false;
 
 
     void FixedUpdate()
     {
         if (isGrounded == true && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
         {
             rb.AddForce(0, jumpForce * Time.deltaTime, 0);
             jumpForce = 0f;
         }
 
     }
     void OnCollisionEnter(Collision other)
     {
         if (other.gameObject.name == "ground")
         {
             Debug.Log("Yes");
             {
                 isGrounded = true;
                 if (isGrounded == true)
                 {
                     jumpForce = 10000f;
                     Debug.Log("Yes");
                 }
             }
         }
     }
 }

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hameed-ullah-jan · Nov 07, 2018 at 02:47 PM

Try this thing: if (isGrounded == true && Input.GetKeyDown(KeyCode.Space)) { rb.AddForce(0, 10000 * Time.deltaTime, 0); isGrounded == false; }

Comment
Add comment · Show 4 · 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 Reissu_Mies · Nov 07, 2018 at 03:22 PM 0
Share

Doesnt seem to work, "Only assignment, decrement, await, and new object expressions can be used as a statement"

avatar image swanijam Reissu_Mies · Nov 07, 2018 at 03:26 PM 0
Share

try using isGrounded = false ins$$anonymous$$d isGround == false in the last line

avatar image Reissu_Mies · Nov 07, 2018 at 04:55 PM 0
Share

@swanijam dont know what youre talking about,they are all isGrounded

avatar image swanijam Reissu_Mies · Nov 07, 2018 at 05:03 PM 0
Share

the symbol "=" vs. "==", not the variable names. I didn't mean to change the capitalization on IsGrounded.

isGrounded = false means "set isGrounded to false" and isGrounded == false means "is isGrounded already set to false?"

the code above does the latter, which causes an error because you can make a conditional statement/question like that outside of an if statement.

avatar image
0

Answer by RustyCrow · Nov 07, 2018 at 07:05 PM

I am understanding your question in 2 ways.
1. "I press space and my character dosent come down" --> check Rigidbody settings. The scripts should work, this feels like you dont have the propper settings/values in the Rigidbody componant. Check mass, drag, gravity.
2. I can press Space even when in the air -> You need to set isGrounded = false; when you press space

if this still dosent help you @Reissu_Mies we will need some more info like what is your expectations and the data surrounding your jump logic.

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

152 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

Related Questions

Touch buttons for step movememt 3 Answers

Accelerometer 2 Answers

MouseLook character is acting wierd 1 Answer

2D Vector Movement,Vectorel Movement with Buttons 2 Answers

HOW TO MAKE A NPC GO FORWAR 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