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 Darkforge317 · May 14, 2018 at 05:01 AM · playergravityjumpingslowfalling

Unity Character Falls Slowly

Hi!

When my character jumps, his fall is really floaty... I made a video of this happening.

I don't understand why this is happening since I don't have anything modifying his upward velocity except for in the Jump() method.

The gravity is -9.81, the default value. Yet I've never had this "slow fall" problem with my other Unity projects, therefore default gravity should be fine.

Here is the entire script... Including my normal movement.

I will also include a shorter version of it that only looks at the jumping.


Movement + Jump Code

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [RequireComponent(typeof(Rigidbody))]
 public class PlayerMovement : MonoBehaviour
 {
     [Header("Movement")]
     [SerializeField]
     private bool _forward;
     [SerializeField]
     private bool _backward;
     [SerializeField]
     private bool _left;
     [SerializeField]
     private bool _right;
     [SerializeField]
     private bool _run;
 
     private Rigidbody _rbody;
 
     public float MaxRunSpeed = 50f, MaxWalkSpeed = 20f;
 
     public float WalkSpeed = 30f, RunSpeed = 60f;
 
     [Header("Jumping")]
     [SerializeField]
     private bool _jump;
 
     [SerializeField]
     private bool _isGrounded;
 
     public float JumpForce = 10f;
 
     // Use this for initialization
     void Start()
     {
         _rbody = GetComponent<Rigidbody>();
         _rbody.constraints = RigidbodyConstraints.FreezeRotation;
     }
 
     private void FixedUpdate()
     {
         // Collect the input for each movement key
         _forward = Input.GetKey(KeyCode.W);
         _backward = Input.GetKey(KeyCode.S);
         _left = Input.GetKey(KeyCode.A);
         _right = Input.GetKey(KeyCode.D);
         _run = Input.GetKey(KeyCode.LeftShift);
         _jump = Input.GetKey(KeyCode.Space);
 
         // If pushing the forward key
         if (_forward)
         {
             // Move forward
             Move(transform.forward);
         }
 
         // If pushing the backward key
         if (_backward)
         {
             // Move backward
             Move(-transform.forward);
         }
 
         // If pushing the left key
         if (_left)
         {
             // Move left
             Move(-transform.right);
         }
 
         // If pushing the right key
         if (_right)
         {
             // Move right
             Move(transform.right);
         }
 
         // If we're grounded
         if (_isGrounded)
         {
             // If pushing jump button
             if (_jump)
             {
                 // Jump!
                 Jump();
             }
         }
         // If we're in the air
         else
         {
             // If our velocity is smaller or equal to 0
             if(_rbody.velocity.y <= 0)
             {
                 // Then we're falling
                 Debug.Log("Falling");
             }
         }
     }
 
     /// <summary>
     /// Moves the player in the passed in direction.
     /// </summary>
     /// <param name="direction">The direction to move in.</param>
     private void Move(Vector3 direction)
     {
         float moveSpeed = 0f;
         float maxSpeed = 0f;
 
         // If we're running
         if(_run)
         {
             moveSpeed = RunSpeed;
             maxSpeed = MaxRunSpeed;
         }
         // If we're not running
         else
         {
             moveSpeed = WalkSpeed;
             maxSpeed = MaxWalkSpeed;
         }
 
         // Add force in the given direction
         _rbody.AddForce(direction * moveSpeed);
 
         // Clamp our velocity so we don't go too fast
         _rbody.velocity = Vector3.ClampMagnitude(_rbody.velocity, maxSpeed);
     }
 
 
     /// <summary>
     /// Makes the player jump in the air using forces.
     /// </summary>
     private void Jump()
     {
         _rbody.AddForce(transform.up * JumpForce);
         _isGrounded = false;
     }
 
     private void OnCollisionEnter(Collision collision)
     {
         if(collision.gameObject.tag == "Ground")
         {
             _isGrounded = true;
         }
     }
 }

Jump Code Only

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [RequireComponent(typeof(Rigidbody))]
 public class PlayerMovement : MonoBehaviour
 {
     [SerializeField]
     private bool _jump;
 
     [SerializeField]
     private bool _isGrounded;
 
     public float JumpForce = 10f;
 
 
     private void FixedUpdate()
     {
         // If we're grounded
         if (_isGrounded)
         {
             // If pushing jump button
             if (_jump)
             {
                 // Jump!
                 Jump();
             }
         }
         // If we're in the air
         else
         {
             // If our velocity is smaller or equal to 0
             if(_rbody.velocity.y <= 0)
             {
                 // Then we're falling
                 Debug.Log("Falling");
             }
         }
     }
 
     /// <summary>
     /// Makes the player jump in the air using forces.
     /// </summary>
     private void Jump()
     {
         _rbody.AddForce(transform.up * JumpForce);
         _isGrounded = false;
     }
 
     private void OnCollisionEnter(Collision collision)
     {
         if(collision.gameObject.tag == "Ground")
         {
             _isGrounded = true;
         }
     }
 }
 

Could someone please tell me why my character is falling slowly?

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

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

155 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Player (Using Player Controller) slow falls when I repeatedly press the jump button while falling., 0 Answers

Bugs on move in air(falling); 0 Answers

Is there a way to prevent camera from falling even though it is a child of the player? 0 Answers

Decreasing Gravity Under Certain Conditions Problem 0 Answers

Detect if falling with custom gravity 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