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 andrewwebber25 · May 10, 2017 at 02:29 PM · collidercollider2djumpingplatformerjumping object

Having Issue with Player Jumping Consistently

Hey guys so im making a platform jumper. Player jumps from platform to platform, avoiding obstacles, very normal stuff. So I created my platform for the player using normal variables like "jump, jumpheight, groundcheck, groundcheckradius" and so on. Player jumps fine (he floats a little too much in the air for my liking). Picture the platform as just a normal rectangle at this point, I only want the top of the rectangle to be "solid" so i change the offset and size of the Box Collider so the player can only stand and jump at the top and will just pass through the rest of the rectangle if they dont jump high enough.

Everything is working fine so I copy and paste the platform to have something for the player to jump to. This platform also works fine. Now I copy and paste a third platform a little higher up, this one i decide to make a little smaller (on the X axis), say instead of being 5ft long like the first two, its only 3ft. The player uses it relatively well but some spots its either a delay when he jumps, or other spots I can click the jump button as much as I want and it still doesnt jump. The specs should all be the same, I literally copy and pasted it. I adjusted the offset and size of the Box Collider for the smaller platform too just to make sure it was still only covering the proper part of the platform. Any suggestions? Ill paste my code, thanks!

 public class Controls : MonoBehaviour {
     public Rigidbody2D rb;
     public float movespeed;
     public bool moveright;
     public bool moveleft;
 
     public bool jump;
     public float jumpheight;
     public Transform groundCheck;
     public float groundCheckRadius;
     public LayerMask whatIsGround;
     private bool onGround;
 
     void Start()
     {
         rb = GetComponent<Rigidbody2D>();
 
     }
 
     void Update()
     {
 
         if (Input.GetKey(KeyCode.LeftArrow))
         {
             rb.velocity = new Vector2(-movespeed, rb.velocity.y);
 
         }
         if (Input.GetKey(KeyCode.RightArrow))
         {
             rb.velocity = new Vector2(movespeed, rb.velocity.y);
 
         }
         if (moveright)
         {
             rb.velocity = new Vector2(movespeed, rb.velocity.y);
         }
         if (moveleft)
         {
             rb.velocity = new Vector2(-movespeed, rb.velocity.y);
         }
         if (Input.GetKey(KeyCode.Space)&&onGround==true)
         {
             rb.velocity = new Vector2(rb.velocity.x, jumpheight);
         }
 
         if (jump)
         {
             rb.velocity = new Vector2(rb.velocity.x, jumpheight);
             jump = false;
         }
         {
             onGround = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
         }
     }
     void FixedUpdate()
     {
         onGround = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
     }
 }
Comment
Add comment · Show 3
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 Valnor · May 10, 2017 at 03:04 PM 1
Share

is it possible that the overlap circle is registering the platform above, and thus preventing the character from jumping? Also not sure what the onGround check within update is doing, it's enclosed with { } but it looks to me like the code would never be accessed at first glance.

avatar image andrewwebber25 Valnor · May 11, 2017 at 03:10 PM 0
Share

Hmm what overlap circle are you referring to exactly? Im not sure why I have onGround check on their twice but when I delete one or the other it doesn't seem to make a difference. It has come to the point where I literally copied the code from the tutorial I am using and it still has the same effects. Its crazy, I have five platforms and the first four work, last one doesn't. The first two are lets say 5' long while the next two are the same platforms copy and pasted but only 3' long. They all work now.

Doesnt seem to matter the length of the platform, i didnt have to edit the offset or anything. Now the fifth one is a duplicate of the 3' long one and you cant jump on it at all. Thats kind of a lie, if you hold the jump button down the player will constantly jump up and down. If i hold down the jump button the whole time from the fourth platform to the fifth, he can jump on the 5th one all day. Its only when I stop and walk on the platform that the player can not jump at all. This is so confusing

avatar image andrewwebber25 Valnor · May 11, 2017 at 03:33 PM 0
Share

Never $$anonymous$$d, I may have figured it out. The tutorial says to set the Ground Check Radius to .1. I bumped it up to .2 and the player seems to jump correctly. Thanks for your help! Had you not brought up the onGround check it may not have led me to that!

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

115 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

Related Questions

Can't jump/buggy when standing next to an object. 0 Answers

How to use Animation Event in this case ? 1 Answer

How to make object with velocity bounce off the obstacles? 0 Answers

Trigger issues 1 Answer

2d Tilemap collidor not working 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