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
2
Question by KraljVipex · Jul 27, 2017 at 03:51 PM · fpsfps controllerfps tutorialfpswalkerfps-controller

Double jump FPS Controller

If in air i press space,when i land jump again.Or if i press space 2 times .How to fix it?

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
1

Answer by Unitykullanici · Aug 26, 2017 at 10:12 AM

Change it on the FPSController.cs!

  void Update () {
        ...
        if (!m_Jump) {
           m_Jump = CrossPlatformInputManager.GetButtonDown ("Jump");
        }
        ...
     }

to

 if (!m_Jump) {
    if (m_CharacterController.isGrounded) {   
       m_Jump = CrossPlatformInputManager.GetButtonDown ("Jump");
    }
 }
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 Sequoia1009 · Sep 03, 2017 at 01:46 PM 0
Share

That just makes the character jump normally again(I tried it). I'll post my script here because it has the same bug, you can check it if you want.

     private bool doublejumppossible;

and

             if (!m_Jump || doublejumppossible == true)
             {
                 if (doublejumppossible == true){
                     doublejumppossible = false;
                 }
                 m_Jump = CrossPlatformInput$$anonymous$$anager.GetButtonDown("Jump");
             }

a last part

             if (m_CharacterController.isGrounded) {
                 doublejumppossible = true;
             }

EDIT: Everything is in void Update except for the private bool and I now know that the if (doublejumppossible == true){ doublejumppossible = false; } is wrong

avatar image Sequoia1009 Sequoia1009 · Sep 03, 2017 at 06:02 PM 1
Share

O$$anonymous$$ here's the script:

public class FirstPersonController : $$anonymous$$onoBehaviour {

     private bool doublejumppossible;
     private bool doublejump;
     private bool prevjumped;

 // Use this for initialization
 private void Start()
 {
   
         prevjumped = false;
 }


 // Update is called once per frame
 private void Update()
 {
     RotateView();
     // the jump state needs to read here to make sure it is not missed
         if (!m_Jump)
     {
             m_Jump = CrossPlatformInput$$anonymous$$anager.GetButtonDown("Jump");
         }
         if (doublejumppossible == true && prevjumped == true) {
             doublejump = CrossPlatformInput$$anonymous$$anager.GetButtonDown("Jump");
         }

         if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
     {
             StartCoroutine(m_JumpBob.DoBobCycle());
         PlayLandingSound();
         m_$$anonymous$$oveDir.y = 0f;
         m_Jumping = false;
     }
     if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
     {
         m_$$anonymous$$oveDir.y = 0f;
     }

     m_PreviouslyGrounded = m_CharacterController.isGrounded;
         if (m_CharacterController.isGrounded) {
             doublejumppossible = true;
             prevjumped = false;
         }
     }


 private void PlayLandingSound()
 {
     m_AudioSource.clip = m_LandSound;
     m_AudioSource.Play();
     m_NextStep = m_StepCycle + .5f;
 }


 private void FixedUpdate()
 {
     float speed;
     GetInput(out speed);
     // always move along the camera forward as it is the direction that it being aimed at
     Vector3 desired$$anonymous$$ove = transform.forward*m_Input.y + transform.right*m_Input.x;

     // get a normal for the surface that is being touched to move along it
     RaycastHit hitInfo;
     Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
                        m_CharacterController.height/2f, Physics.AllLayers, QueryTriggerInteraction.Ignore);
     desired$$anonymous$$ove = Vector3.ProjectOnPlane(desired$$anonymous$$ove, hitInfo.normal).normalized;

     m_$$anonymous$$oveDir.x = desired$$anonymous$$ove.x*speed;
     m_$$anonymous$$oveDir.z = desired$$anonymous$$ove.z*speed;

         if (doublejump == true) {
             m_$$anonymous$$oveDir.y = m_JumpSpeed;
             m_Jump = false;
             m_Jumping = true;
             doublejumppossible = false;
             doublejump = false;
         }
         if (m_CharacterController.isGrounded)
     {
         m_$$anonymous$$oveDir.y = -m_StickToGroundForce;

        if (m_Jump)
         {
             m_$$anonymous$$oveDir.y = m_JumpSpeed;
             PlayJumpSound();
             m_Jump = false;
             m_Jumping = true;
                 prevjumped = true;
             }
     }
     else
     {
                 m_$$anonymous$$oveDir += Physics.gravity * m_Gravity$$anonymous$$ultiplier * Time.fixedDeltaTime;
         }
     m_CollisionFlags = m_CharacterController.$$anonymous$$ove(m_$$anonymous$$oveDir*Time.fixedDeltaTime);

     ProgressStepCycle(speed);
     UpdateCameraPosition(speed);

     m_$$anonymous$$ouseLook.UpdateCursorLock();
 }

Removed most of the script because character limit...

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

127 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

Related Questions

How to Make the FPS Character Controller Prone 1 Answer

Allow player to slide off of platform, 0 Answers

Problema multiplayer al agregar vehiculo 0 Answers

Object position/rotation after animation has finished to play. 1 Answer

How do I make the FPScontroller stop moving EXACTLY when I stop holding a key? (as opposed to waiting to complete a step before stopping) 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