Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by monhoo2468 · Apr 13, 2019 at 08:47 AM · character controller

Character controller is not grounded

I just write it infinity runner character script but My character doesn't fall or can't jump too How can i fix this.https://youtu.be/kgHXjj9xj9c

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by metalted · Apr 13, 2019 at 09:19 AM

I think it is because you have your direction variable inside of the Update function. This will always set the direction.y to 0 (line 28). Your script is very similar to the example script in the scripting reference, but there are some differences that is making it not work. Check out the link below and compare. Following that example will probably fix your problem.


https://docs.unity3d.com/ScriptReference/CharacterController.Move.html

Comment
Add comment · 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
0

Answer by SpellMender · Oct 29, 2021 at 04:38 PM

Bump. I am having the exact same problem. I even copy/pasted the exact script found at the link provided by @metalted but it is still inconsistently grounded; seemingly at arbitrary times. The transform on my end is always at 1.08 when it SHOULD be grounded. At this point I just want to make my own ground detection script; but that defeats the purpose of having a Character Controller component in the first place. Any recommendations, or is this a bug in need of fixing?

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 SpellMender · Feb 09 at 02:16 AM 0
Share

Solved it.

Whatever is happening to detect gravity happens in CharacterController.Move(). It was this thread from back in 2018 that made me realize this: https://answers.unity.com/questions/1492717/charactercontroller-isgrounded-confusion.html

TLDR make sure you're doing two things: 1. Check for grounding AFTER you call CharacterController.Move() 2. Keep a little force applied even when you ARE grounded.

I generally set normalForce to 1.

Here's my code:


public class Player : MonoBehaviour { [SerializeField] float gravity = 9.8f, normalForce = 1f;

 float gravVelocity;
 
 CharacterController character;

 void Start()
 {
     character = GetComponent<CharacterController>(); // References the Character Controller
 }

 void Update()
 {
     UpdateGravity(); // Gravity is added to player movement
 }

 // The character moves downward (negative up) at velocity (gravVelocity) per second (deltaTime)
 void UpdateGravity() {
     character.Move(gravVelocity * Time.deltaTime * -transform.up);  // Move() must be called before isGrounded              <--|| required for proper   ||
     if (character.isGrounded) { gravVelocity = normalForce; }       // A static normal force must be applied when grounded  <--|| ground detection      ||
     else { gravVelocity += gravity * Time.deltaTime; } // increase gravVelocity by meters (gravity) per second (deltaTime)
 }

}


avatar image SpellMender SpellMender · Feb 09 at 02:16 AM 0
Share

Also I'm a total newb at placing code blocks. Any suggestions for the future?

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

103 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

Related Questions

Character Controller NOT COLLIDING. 0 Answers

2D Character suddenly stops moving for no given reason 1 Answer

Changing the Speed of CharacterController.Move(Vector3.forward) 1 Answer

Why won't this jump code work? 1 Answer

How to apply the character controller I had bought to a character of my own 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