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 /
avatar image
0
Question by BlankSlates · Jul 12, 2018 at 10:49 PM · transformrigidbody2dphysics2djumpingforce

Inconsistent jump height and double jumping issues with rigidbody2D on a sprite

Basically i cant figure out how to get my jumping to work without having issues. If i use update like .. private int jumpCount public int maxJumps and have it count down along with using a isGrounded bool then i can prevent double jumps in update function fairly consistently. However every fourth or so jump the jump will randomly go up about twice as high if im using update regardless of jumpStrength not changing. So i tried using fixed update.. it did not go well. Basically in fixed update everything is even worse. Regardless of whether i use a isGrounded bool with a ground tag or the counter or both it seems pretty random as far as the jump cooldown is concerned and still attempts to double jump somewhat randomly if your spamming the space key. Any suggestions? Heres a look at what i have if you like .

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class Player : MonoBehaviour
 {
 [SerializeField]
 private int JumpCount = 0;
 [SerializeField]
 private int MaxJumps = 1; //max amount you can jump ie 2 for double jump

// private bool isGrounded;

 [SerializeField]
 private float jumpStrength = 20f;

 [SerializeField]
 private bool dead;

 [SerializeField]
 private float defaultAnglespeed = 0f;

 [SerializeField]

 private float anglespeed = 30.0f;

 [SerializeField]
 private float moveSpeed = 100f;
 
 private Rigidbody2D rb2D;



 

 // Use this for initialization
 void Start ()
 {
     rb2D = GetComponent<Rigidbody2D>();
     JumpCount = MaxJumps;
 }

 private void FixedUpdate()
 {

     walk();

     if (dead != true)
     {
         rb2D.MoveRotation(defaultAnglespeed * Time.fixedDeltaTime);
     }
     else if (dead == true)
     {

     }





 }
 // Update is called once per frame
 void Update ()
 {
     
 }

 private void walk()
 {
     if ( Input.GetKey("d"))
     {
         if ( dead != true)
         rb2D.AddForce(transform.right * moveSpeed * Time.deltaTime);
         rb2D.MoveRotation(-5f + anglespeed * Time.fixedDeltaTime);
        
         
     }

     else if (Input.GetKey("a"))
     {
         if (dead!=true)
         rb2D.AddForce(-transform.right * moveSpeed * Time.deltaTime);
         rb2D.MoveRotation(5f + anglespeed * Time.fixedDeltaTime);
     }


     else if (Input.GetKeyDown("space") == true) //&& isGrounded
     {
         if (JumpCount > 0 )

         {
             
             rb2D.AddForce(transform.up * jumpStrength );
             JumpCount = JumpCount - 1;
         }

         else if (JumpCount <= 0)
          {

          }
         
     }


 }

 private void OnCollisionEnter2D(Collision2D collision)
 {
     switch (collision.gameObject.tag)
     {
         case "floor":
             {
                 JumpCount = MaxJumps;
                // isGrounded = true;
                 //print("I'm touching the ground");
                
                 return;
             }

         default:
             {
                     //isGrounded = false;
             }
             return;


           
     }

 }

}

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

· Add your reply
  • Sort: 

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

172 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 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

Addforce trajectory 0 Answers

RiigidBody2D.AddForce() isnt working at all. 0 Answers

how can i make my player jump to fixed position contenously 0 Answers

Rigidbody2D.Cast() against mutiple colliders with a single Rigidbody2D 0 Answers

Weird Jump After Walking Into Wall and Releasing 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