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 /
This question was closed Dec 21, 2020 at 03:44 PM by InfernoGamingYT for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by InfernoGamingYT · Dec 20, 2020 at 05:42 AM · shooter2d platformer

character able to jump non-stop

My character can jump as much as they want. i dont want that, i only want a double jump. here is my code.

 public float speed;
 public float jumpForce;
 public float moveInput;
 public Transform groundCheck;
 public float checkRadius;
 public LayerMask whatIsGround;
 public int extraJump;
 public int ejV;

 private bool isGrounded;
 private bool facingRight = true;
 private Rigidbody2D rb;

 void Start()
 {
     extraJump = ejV;
     rb = GetComponent<Rigidbody2D>();
 }

 void Update()
 {
     if (isGrounded == true)
     {
         extraJump = ejV;
     }

     if (Input.GetKey(KeyCode.Space) && extraJump > 0)
     {
         rb.velocity = Vector2.up * jumpForce;
         extraJump--;
     }
     else if (Input.GetKey(KeyCode.Space) && extraJump == 0 && isGrounded == true)
     {
         rb.velocity = Vector2.up * jumpForce;
     }
 }

 void FixedUpdate()
 {
     
     isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
     moveInput = Input.GetAxis("Horizontal");
     rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
     if (facingRight == false && moveInput > 0)
     {
         Flip();
     }
     else if (facingRight == true && moveInput < 0)
     {
         Flip();
     }
 }

 void Flip()
 {
     facingRight = !facingRight;
     Vector3 Scaler = transform.localScale;
     Scaler.x *= -1;
     transform.localScale = Scaler;
 }
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

  • Sort: 
avatar image
0

Answer by Hawaii_Dev · Dec 20, 2020 at 11:55 AM

Have you checked so "checkRadius" is not to big and that "whatIsGround" has the right layermasks. Other than that add the line "isGrounded = false" in the if statement where you jump.

Comment
Add comment · Show 1 · 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 InfernoGamingYT · Dec 20, 2020 at 08:49 PM 0
Share

sooo, im kinda a noob at coding(just started back up recently), ik a little bit, but not much XD. no matter how big or small the checkradius is, it doesnt change the jumping. And i have no clue if i put the isGrounded = false in the right place(its in the if statement in jumping tho). and the ground is on the right layermask.

Follow this Question

Answers Answers and Comments

111 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

Related Questions

2D Platformer - Plane/GUITexture/or? 1 Answer

How to use accelerometer in a 2d game 1 Answer

Mirroring Animation with Object Move 2 Answers

2d platfromer player controller will not jump 0 Answers

Adding force to mouse position adds force relative to screen center 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