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 /
avatar image
0
Question by awts202 · Mar 21, 2018 at 06:50 PM · jumpingballconfused

Problem with simple jumping.

Hello, I've been stuck on this problem so much and I can't find a solution. So I have a ball that moves around completely fine but jumping isn't working it supposed to. It jumps fine EXCEPT on FLAT surface. I find this very odd ( I'm losing my mind can't find a way to make it work). I've put up some images for you to see. images

This is my whole player script.

public class BasicMovement : MonoBehaviour {

 public float speed;
 public float desiredMaxSpeed;
 public float jumpHeight;
 public float airHover;
 
 private Rigidbody rb;
 private bool grounded;
 private bool isjumping;
 private bool isMoving;
 
 
 void Start()
 {
     rb = GetComponent<Rigidbody>();
 }
 
 
 
 void OnCollisionStay(Collision col)
 {
     if (col.gameObject.tag == "Walls")
         grounded = false;
     else
     grounded = true;
     isMoving = true;
 
 }
 
 void OnCollisionExit(Collision col)
 {
     grounded = false;
     isMoving = false;
 }
 
 
 void Update()
 {
     if(Input.GetButton("Jump") && grounded == true)
     {
         isjumping = true;
     }
 }
 
 void FixedUpdate()
 {
     if (isMoving == true)
     {
         Movement(speed);
         manipulateSpeed(desiredMaxSpeed);  
     }
         Movement(airHover);//ball moves a bit while in air.
     if (isjumping == true)
     {
         BallJumping();
     }
 }
 void manipulateSpeed(float maxSpeed) //this change the maxSpeed of the ball.
 {
     if (rb.velocity.magnitude > maxSpeed)
     {
         rb.velocity = rb.velocity.normalized * maxSpeed;
     }      
 }
 
 public void Movement(float currentSpeed)
 {
     float moveHorizontal = Input.GetAxis("Horizontal");
     float moveVertical = Input.GetAxis("Vertical");
 
     Vector3 movement = new Vector3(moveHorizontal ,0, moveVertical  )*currentSpeed;
     rb.AddForce(movement * currentSpeed * Time.deltaTime);  
 }
 void BallJumping()  
 {
     rb.velocity = rb.velocity+Vector3.up * jumpHeight;
     isjumping = false;
 }

}Note: I increase my gravity to fall faster.

Can someone test this. I don't know why this is happening.

Comment
Add comment · Show 2
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 Nomenokes · Mar 23, 2018 at 11:59 PM 0
Share

Does the problem still happen with the walls removed?

avatar image awts202 Nomenokes · Mar 24, 2018 at 11:39 AM 0
Share

Yeah, removing walls doesn't fix it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by foxtrot117 · Mar 24, 2018 at 01:22 AM

Your problem is probably the OnCollisionStay(). First of all be sure that ground is not tagged as "walls". Also mind that if player comes in contact with walls while he is suppose to be grounded, his state will change to "not grounded" because OnCollisionStay() is triggered(it triggers after OnCollisionEnter() which is almost immediately). Then your player will need to get separated from the ground and then contact it again so grounded variable is reset to true.

I would suggest to change the method you use for detection and go for Physics.Raycast() which is much more commonly used. This because a lot of issues can be avoided, many of which cannot be noticed or said. Just Raycast() a line to -Vector3.up and check if it collides with the ground.

-Hope i helped

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 awts202 · Mar 24, 2018 at 01:02 PM 0
Share

Sadly, using Raycast didn't solve it. Physics.Raycast(transform.position, -Vector3.up, dist + 0.01f); Jump still slows on flat surface and one thing that I found out is that changing GetButton to GetButtonDown is making the ball completely unable to jump high in any ground.

avatar image Nomenokes awts202 · Mar 24, 2018 at 01:23 PM 0
Share

Aha! If changing the getbutton to getbuttondown makes it not able to jump high on any ground, that means your force adding is being called more than once on uneven ground. The problem isn't that you are jumping too low on flat ground, it's that you are jumping too high on uneven ground. Change it to GetButttonDown as you said, and just increase jump height. Then it should be consistently high.

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

77 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

Related Questions

i want to move a ball on z axis and jump on y axis , 2 Answers

Ball rolling across boxes randomly jumping 1 Answer

I Have A Jump Script, But I need to Edit it To Where The Player Is Only Limited To One Jump 2 Answers

Ball Rolling Game Help 0 Answers

How to stop multiple mid-air jumps on a gameObject? 4 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