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 PvTGreg · Feb 03 at 04:57 PM · charactercontrollergrounded

Character Controller is never Grounded

Hi,

So my character controller.isgrounded is never true. ive tried the basic way of just using isgrounded but the controller never is. ive tried using Kurt-Dekker solution on the fourms but that does not work either as the verticle velocity constantly goes down ie its not grounded. i have a very simple character with no colliders just the controller. not sure if this is a bug in unity or something else. here is my current code

   private CharacterController controller;
     private Transform cam;
     public Animator anim;
 
     public bool playerRunning;
     public float playerCurrentSpeed = 3.0f;
     public float playerSpeed = 3.0f;
     public float playerRunSpeed = 5.0f;
     public bool canMove;
     private Vector3 playerVelocity;
     private float verticalVelocity;
     private float groundedTimer;
     private bool groundedPlayer;
     public float jumpHeight = 1.0f;
     private float gravityValue = 9.81f;
 
     public float turnSmoothTime = 0.1f;
     float turnSmoothVelocity;
     Vector2 playerMoveDir;
     Vector2 playerLookDir;
 
     public Renderer robot;
     public AudioSource tracksAudio;
 
     bool Beenhit;
     private float nextActionTime = 0.0f;
     public float movementSlowPeriod = 2f;
 
 
     InputMaster input;
     // Start is called before the first frame update
     private void Awake()
     {
         cam= Camera.main.transform;
         input = new InputMaster();
         input.Player.Move.performed += ctx => playerMoveDir = ctx.ReadValue<Vector2>();
         input.Player.Look.performed += ctx => playerLookDir = ctx.ReadValue<Vector2>();
         input.Player.Run.performed += ctx => playerRunTrigger();
         controller = gameObject.GetComponent<CharacterController>();
     }
     void FixedUpdate()
     {
         groundedPlayer = controller.isGrounded;
         if (canMove)
         {
             playerMovmentThirdPerson();
         }
         if (Beenhit)
         {
             playerCurrentSpeed = playerCurrentSpeed / 2;
             if (Time.time > nextActionTime)
             {
                 nextActionTime += movementSlowPeriod;
                 playerCurrentSpeed = playerSpeed;
                 Beenhit = false;
             }
         }
     }
     void playerMovmentThirdPerson()
     {
 
         Vector3 move = new Vector3(0,0,0);
         bool groundedPlayer = controller.isGrounded;
         if (groundedPlayer)
         {
             // cooldown interval to allow reliable jumping even whem coming down ramps
             groundedTimer = 0.2f;
         }
         if (groundedTimer > 0)
         {
             groundedTimer -= Time.deltaTime;
         }
 
         // slam into the ground
         if (groundedPlayer && verticalVelocity < 0)
         {
             // hit ground
             verticalVelocity = 0f;
         }
 
         // apply gravity always, to let us track down ramps properly
         verticalVelocity -= gravityValue * Time.deltaTime;
 
 
         if (input.Player.Jump.triggered)
         {
             // must have been grounded recently to allow jump
             if (groundedTimer > 0)
             {
                 // no more until we recontact ground
                 groundedTimer = 0;
                 // Physics dynamics formula for calculating jump up velocity based on height and gravity
                 verticalVelocity += Mathf.Sqrt(jumpHeight * 2 * gravityValue);
             }
            
         }
         //Player Moving And turning
         Vector3 direction = new Vector3(playerMoveDir.x, 0, playerMoveDir.y);
         if (direction.magnitude >= 0.1f)
         {
             float targetAgnle = Mathf.Atan2(direction.x,direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
             float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAgnle, ref turnSmoothVelocity,turnSmoothTime);
             transform.rotation = Quaternion.Euler(0f, angle, 0f);
 
             Vector3 moveDirection = Quaternion.Euler(0f, targetAgnle, 0f) * Vector3.forward;
             move = moveDirection.normalized;
         }
         move.y = verticalVelocity;
 
         controller.Move(move * playerCurrentSpeed * Time.deltaTime);
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 Shaolin-Dave · Feb 03 at 07:14 PM 0
Share

I noticed that you have code copying controller.isGrounded to groundedPlayer on both lines 43 and 63. In the case of 63, it re-initializes the variable. I don't know how that doesn't throw an error itself.

But in your question you said "character controller.isgrounded is never true", so that specific issue isn't in this class anyway. It's on the CharacterController component.

How does that deter$$anonymous$$e isgrounded? The cause could be different based on if it's using a collider or raycast, for example. Most likely, whatever you're using to detect the character's collision with the ground is probably in the wrong place. Make sure it's by the character's feet, and all layers are appropriately assigned.

avatar image PvTGreg Shaolin-Dave · Feb 03 at 07:20 PM 0
Share

so im using the default character controller that unity provides. even with a bog standard capsule with movement the isgrounded varaible of the character controller is very rarely true. sometimes it works for a few jumps then it stops working for ages.

with all layers default.

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

150 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

Related Questions

I have a issue with Player Grounding. 1 Answer

Character Jumping Not Working Sometimes 1 Answer

How should I check if the charactercontroller is grounded next in the next calculation? 1 Answer

Let Character Controller jump. 0 Answers

Let Character Controller 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