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 /
  • Help Room /
avatar image
1
Question by FpsLukonja · Aug 24, 2013 at 12:16 PM · double jumpwall jumpdodge

Double Jump Not Working Good

My double jump script works however after a while, to be more specific after jumping around my scene, suddenly i can't double jump anymore, and only 1 jump works then. Can someone check whats wrong? I am also trying to get my FPS player to walljump, and gain jumping movement speed while jumping, which slows down after i stop jumping.

Also my air control is massive and i notice there is no gravity when i jump from boxes i jst fall down, can someone help, or point me to what am i doing wrong? Here is my movement script by following tutorials etc. I am trying to get feeling as between quake and unreal tournament genres.

    using UnityEngine;
     using System.Collections;
     
         [RequireComponent(typeof(CharacterController))]
         public class FPSController : MonoBehaviour
         {
         public float movementSpeed = 5.0f;
         public float jumpSpeed = 8.0f;
         int jumpCount = 0;
         int maxJumps = 1;
         float verticalVelocity = 0;
         
         CharacterController characterController;
         
         void Awake () {
             Screen.lockCursor = true;
             characterController = GetComponent<CharacterController>();
         }
         
          
             void Update()
             {
          
          
             float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
             float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;
             
             verticalVelocity += Physics.gravity.y * Time.deltaTime;            
     
             
             if( characterController.isGrounded && Input.GetButtonDown("Jump") ) {
                 verticalVelocity = jumpSpeed;
                 jumpCount++;        
             }
             
             if(jumpCount==maxJumps && !characterController.isGrounded && Input.GetButtonDown("Jump") ) {
                 verticalVelocity = jumpSpeed;
                 jumpCount=0;
             }
             
             Vector3 speed = new Vector3( sideSpeed, verticalVelocity, forwardSpeed );
             
             speed = transform.rotation * speed;
             
             characterController.Move( speed * Time.deltaTime );
             
                  
         }
     }
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
2
Best Answer

Answer by -hiTo- · Aug 24, 2013 at 03:39 PM

I see a problem with your if-statements.

What if you only jump once, then you're back on the ground. Then you do it again. Then you do it again.

Your jumpCount would be 3, and your second if-statement would never run.

Set your jumpCount in your first if statement to 0, and it should solve the problem.

Just a tip: If you use a bool, you would only need 1 variable, instead of 2 integers. Example:

 private bool HasDoubleJumped = false;
 
 private void Update()
 {
     if (characterController.isGrounded && Input.GetButton("Jump"))
     {
         verticalVelocity = jumpSpeed;
         HasDoubleJumped = false;
     }
     else if (!HasDoubleJumped && !characterController.isGrounded && Input.GetButton("Jump"))
     {
         verticalVelocity = jumpSpeed;
         HasDoubleJumped = true;
     }
 }
Comment
Add comment · Show 2 · 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 FpsLukonja · Aug 24, 2013 at 04:40 PM 0
Share

Thank you, it worked! I was thinking all day how to do this. And you solve it in few $$anonymous$$utes. Here is solution.

 if(characterController.isGrounded && Input.GetButtonDown("Jump") ) {
                 verticalVelocity = jumpSpeed;
                 jumpCount=0;        
             }
             
             if(jumpCount<maxJumps && !characterController.isGrounded && Input.GetButtonDown("Jump") ) {
                 verticalVelocity = jumpSpeed;
                 jumpCount=1;
             }
avatar image -hiTo- · Aug 24, 2013 at 05:16 PM 0
Share

Please mark the answer as correct. Thanks!

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

16 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

Related Questions

double jumping after falling off edge problem 1 Answer

I can't get my character to stop double jumping. 0 Answers

How to do dodge Unity2D like Crossing Souls or Hyper Light Drifter. 0 Answers

My player is double jumping when it should not be able to. I am not sure what is allowing it to do so. 0 Answers

How to move upward with wall jump and not be pulled down too quickly? 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