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 /
avatar image
0
Question by jageleo · Feb 06, 2021 at 01:57 PM · 2d gamejumpjumpingjumping object

I need help with fixing my "up special" mechanic.

Recently i learnt how to make a double jump mechanic, and i wanted to challenge myself and create a up-special one. But for some weird reason i can do 2 up-specials after each other which is quite annoying.

Important variables public float jumpForce;

 public bool isGrounded;
 public Transform groundCheck;  
 
 private int extraJumps;
    public int extraJumpValue = 1;
 
  private bool LookUp;
     private int AmountOfUpSpecial;
     public int AmountOfUpSpecialValue;
 

Void start function

 void start()
     {
         extraJumpValue  = 1;
         extraJumps = extraJumpValue;
 
         AmountOfUpSpecialValue = 1;
         AmountOfUpSpecial = AmountOfUpSpecialValue;
 
         rb = GetComponent<Rigidbody2D>();
     }

My fixed Update function(dont think its that important)

  void FixedUpdate()
     {
 
         
         //Player 1 movement
 
         isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
         
         if (P1 == true)
         {
         if (Input.GetKey("d"))
         {
             if(isGrounded == false)
             {
                 moveInput = 1;
                 rb.velocity = new Vector2(moveInput * speed / 1.4f, rb.velocity.y);
             }
             else if (isGrounded == true)
             {
                  moveInput = 1;
                  rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
             }
         }
         else
         {
             rb.velocity = new Vector2(0, rb.velocity.y);
         }
 
         if (Input.GetKey("a"))
         {
                 if(isGrounded == false)
             {
                 moveInput = -1;
                 rb.velocity = new Vector2(moveInput * speed / 1.4f, rb.velocity.y);
             }
             else if (isGrounded == true)
             {
                  moveInput = -1;
                  rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
             }
         }
 
 
         }
 
             //Player 2 movemt
 
         if (P1 == false)
         {
         if (Input.GetKey("right"))
         {
                 if(isGrounded == false)
             {
                 moveInput = 1;
                 rb.velocity = new Vector2(moveInput * speed / 1.4f, rb.velocity.y);
             }
             else if (isGrounded == true)
             {
                  moveInput = 1;
                  rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
             }
         }
         else
         {
             rb.velocity = new Vector2(0, rb.velocity.y);
         }
 
         if (Input.GetKey("left"))
         {
                 if(isGrounded == false)
             {
                 moveInput = -1;
                 rb.velocity = new Vector2(moveInput * speed / 1.4f, rb.velocity.y);
             }
             else if (isGrounded == true)
             {
                  moveInput = -1;
                  rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
             }
         }
         }
         //Flip function
         if (facingRight == false && moveInput > 0)
         {
                 Flip();
         }
          else if (facingRight == true && moveInput < 0)
         {
             Flip();
         }
     }

My Update function + my ground == true function.

 void Update()
     {
         //Moves
 
         //Up special
     if(P1 == true)
     {
          if(Input.GetKey("w"))
         {
             LookUp = true;
         }
         else
         {
             LookUp = false;
         }
     }
     if (P1 == false)
     {
          if(Input.GetKey("up"))
         {
             LookUp = true;
         }
         else
         {
             LookUp = false;
         }
     }
 
         //Jumping
         if (P1 == true)
         {
             if(Input.GetKeyDown(KeyCode.Space))
             {
                 if(LookUp == true && AmountOfUpSpecial > 0)
                 {
                     rb.velocity = Vector2.up * jumpForce * 2;
                     AmountOfUpSpecial = 0;
                     extraJumps = 0;
                 }
                 else if (LookUp == false  && extraJumps > 0)
                 {
                     rb.velocity = Vector2.up * jumpForce;
                     extraJumps =- 1;
                 }
                 else
                 {
                     print("You cant jump!");
                 }
             }
         }
         else if (P1 == false)
         {
             if(Input.GetKeyDown(KeyCode.I))
             {
                 if(LookUp == true && AmountOfUpSpecial > 0)
                 {
                     rb.velocity = Vector2.up * jumpForce * 2;
                     AmountOfUpSpecial -= 1;
                 }
                 else if (LookUp == false  && extraJumps > 0)
                 {
                     rb.velocity = Vector2.up * jumpForce;
                     extraJumps--;
                 }
             }
         }
 
 
         
         if(isGrounded == true)
         {
             extraJumps = extraJumpValue;
             AmountOfUpSpecial = AmountOfUpSpecialValue;
         }
     }


If you need any more info i can provide, and yes i am new to game dev.

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
0

Answer by logicandchaos · Feb 06, 2021 at 02:11 PM

line 44 looks like it should be extraJumps -= 1; instead of extraJumps =- 1;

Do you only get one extra extra jump? like can you special jump > than 2 times? if so you might have to change a to a =

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

144 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

Related Questions

Raycast2D not working 1 Answer

Long press for charged Jump 1 Answer

Another Slow Fall Problem... 2 Answers

[Solved] Having trouble with 2D Character Jump using Bolt 0 Answers

change multiple jump to single jump 1 Answer


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