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 stingman · May 13, 2012 at 01:00 AM · collisioncharactercontrollercontrollercollisionflags

Problem detecting ground with collision flags and controller.move (vector3.down)

I am using a character controller and after the character controller double jumps if you press jump a third time he does an "air smash." Kind of mario style. If the ground is visible it works fine. But if I can't see the ground below the character he will perform the air smash but will not detect a collision when he hits the ground and therefore goes right through the ground... I'm stuck trying to figure out why. My script is very long so here is the bits pertaining to what I'm trying to accomplish.

 if (!airSmashing) {
     collisionFlags = controller.Move (direction * speed + Vector3 (0, verticalSpeed, 0) + inAirVelocity;);
     }
 
 if (airSmashing) {
     canControl = false;
     controller.Move (Vector3.down* 100 * Time.deltaTime);
     if (controller.isGrounded) {
     airSmashing = false;
     canControl = true;
     }
     }

Any suggestions?

Comment
Add comment · Show 4
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 syclamoth · May 13, 2012 at 01:03 AM 0
Share

What do you mean by 'can't see the ground'? Is it off the edge of the camera? Does this only happen when the character is a certain distance away from the ground?

avatar image stingman · May 13, 2012 at 01:13 AM 0
Share

Yes this only happens when the ground is off the edge of the camera... even if it's just so slightly out of view of the camera.

avatar image Fraggle222 · May 13, 2012 at 01:25 AM 0
Share

The collisionFlags variable in your script above, is that just your own variable? It's not, for example the character controller's collisionFlags, which you should not set yourself, right?

avatar image stingman · May 13, 2012 at 01:35 AM 0
Share

yes it's my own variable... but I've been messing around a bit and it turns out it happens when he's above a specific distance away from the ground. The camera view doesn't actually have anything to do with it. Seems to be about 10 meters he collides with the ground... anything beyond that he falls through

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by stingman · May 18, 2012 at 11:12 PM

Alright, so I solved the problem. The issue the character controller was having was not being able to detect a collision based on other aspects of my script. I'm still somewhat shaky on this. BUT, I did get an air smash to work. Not as smooth as mario yet but I'm sure this will definately help others trying to do the same thing. Enjoy: (put this in your update function:

 if (airSmashing) {
 canControl = false; // disable any controls for the player
 controller.Move (Vector3.down * 10000 * Time.deltaTime);
 if (CollisionFlags.CollidedBelow) {
 airSmashing = false;
 canControl = true;
 controller.Move (//whatever your normal move code is);
 }
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 Bunny83 · May 18, 2012 at 11:42 PM 0
Share

It's fine that you kind of fixed your problems, but this doesn't make much sense ;)

CollisionFlags.CollidedBelow is just a constant value (actually it's just a value of 4). That means your whole if statement equals:

 if (true)
 {

which makes the whole "if" useless so the code is executed anyway.

As far as i know controller.isGrounded and controller.collisionFlags == CollisionFlags.CollidedBelow is actually exactly the same. Usually it should work, are you sure that you don't move the ground upwards or something like that so that not the character goes through the ground but the ground through the player?

I can't think of much other reasons except that you manually disabled the collision (layerbased collision matrix or IgnoreCollision).

Note that CharacterController.detectCollisions has no effect on the collision detection of the controller itself. It just disables the collider capsule for other objects. $$anonymous$$ove or Simple$$anonymous$$ove will detect collsions anyway.

avatar image stingman · May 20, 2012 at 12:33 AM 0
Share

ya I don't fully understand why my solution works... it just does. Your post helped me understand this a little more though. Anyhow the problem was not that the ground was moving through the player. the player went through the ground and somehow his position was transformed up on the y axis by an immense amount of units at which point gravity was reactivated and the player would fall at his ter$$anonymous$$al velocity back to the ground. By immense units I mean at least 1000 units each time.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Ceiling collision detection 0 Answers

How to determine a collision incase of two Character-Controller. 0 Answers

How does unity character controller work? 0 Answers

Disable collision between mesh collider and character controller 3 Answers

Voxel engine physics 3rd person character controller 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