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
1
Question by JeremyG · Feb 02, 2013 at 08:10 PM · playercharactercontrollerfallingunity4

Help! Problems with Character.isGrounded in Unity 4.0.1?

Hi everyone,

I want to make a "PlayerManager" script that handles things like death falls, respawns, scores, etc., and I've done this before in Unity 3 utilizing the CharacterController based off of a script posted here, but now it doesn't seem to work in Unity 4. Here's my version of that same script:

 #pragma strict
 var fallDistance: double = 3;
 var deathFall: double = -15;
 var falling: boolean = false; 
 var lastY: float;    
 private var character: CharacterController;
 
 function Start()
 {
   character = GetComponent(CharacterController);
   lastY = transform.position.y;
 }
 
 function Update()
 {
       if (character.isGrounded == false)
       { 
         falling = true;
       } 
       if (character.isGrounded == true)
       {
           falling = false;
         lastY = transform.position.y;
       }
   
       if (falling)
       {            
           var fall: double = lastY - transform.position.y;
         if (fall > fallDistance)
         {            
             fall = 0.0;
             falling = false;
             Debug.Log("OUCH!");
         }
       }
 }

The problem I am having is that the boolean "falling" flashes between states while the game is running - it's like there's something wrong in the CharacterController class in which it's updating between both states, even while the player is perfectly grounded! As a direct result, sometimes the player will fall and the "OUCH" text will not get outputted to the console, even though they fell above the allowed amount. Has anyone else encountered any problems like this, or is there something I'm doing wrong in the script? Although I just tried that original script and it doesn't work either, so something seems to be afoot! I'm running Windows 8 64bit, if that might have anything to do with it?

If anybody has any solutions I would greatly appreciate it! :D

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by JeremyG · Feb 03, 2013 at 09:44 AM

Ok, so I just tried it in Unity 3 and it isn't working there either! What on earth could be the problem with isGrounded? And why is it cross-version? I've never had this much trouble with it before. I've upgraded to Windows 8, does anybody know if that's maybe the problem?

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 schaddemm · Feb 02, 2013 at 10:42 PM

Safest solution is to implement your own isgrounded function. You could make a raycast to the ground. Or you could in I think OnCollisionEnter() test the hit.normal (see character motor script). Or you could use a trigger collider at the feet of your character.

As to why isgrounded isn't giving constant results, that's weird. Test with OnCollisionEnter if we really aren't colliding with anything. I'm especially thinking about stuff like your character colliding with it's weapon.

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 Loius · Feb 02, 2013 at 11:19 PM

What do your move commands look like? Technically you're not falling until your Y velocity is negative, so a slight physics fluctuation can make your code think it is-isn't falling at times.

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 JeremyG · Feb 03, 2013 at 02:54 AM 0
Share

This is the only script I've written so I don't have my own movement commands implemented, just the stuff based off the script I linked to in my original post.

This technique worked perfectly in Unity 3.5.x, so I'm thinking it's definitely something in the update that's causing issues. It's just frustrating to know that I had it working in the previous version. Personally, I was hoping it would be a fault in my code, but that doesn't appear to be the case. :P

I'll just look into writing my own isgrounded function like schaddemm suggested, and let everyone know what works or not. If it works, I'll be sure to post it so that if anyone else encounters this problem, the answer won't be far away! :)

avatar image JeremyG · Feb 04, 2013 at 12:44 AM 0
Share

O$$anonymous$$, so I posted a thread about it over in Unity Support, and it seems to be that the Physics engine in Unity isn't updating properly. I've attempted casting a ray to act as a "feeler" for the ground, and it's flashing between states, just like the default isGrounded variable! $$anonymous$$ore information is available in that thread.

I'm also now attempting this in Unity 3.5.6f4, just because I'm more comfortable with it. It doesn't matter what version I use, I'm always getting this problem! Very frustrating.

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

11 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

Related Questions

How to make player not fall during dash 1 Answer

Moving Platform and CharacterController.Move not working. The player falls 3 Answers

Simulating the Character Controller? 0 Answers

Character Controller Falls through Mesh Collider ground and objects in 3.1 2 Answers

Checklist: Object or Character is falling through the floor 12 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