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 Xatoku · Jul 25, 2012 at 06:30 AM · collisioncollidercharactergrounded

Grounded Only on One Layer

I've got my character grounded properly, but I don't want him considering standing on top of another person as ground. It's hard to explain, but basically, the character flies. So when he stops flying, he'll float down to the ground. My problem is that if he were fighting mid-air and accidentally collided above an enemy, he would act as if that enemy is the ground, and ground himself, thus stopping him from flying.

What I want him to do in that situation is to not consider that person as ground, and simply continue flying. So I essentially want to limit what the character see's as being "grounded" to a selected layer mask. If anybody got through my mess of an explanation, here's what I'm working with:

//Apply gravity moveDirection.y -= gravity Time.deltaTime; //Move controller var controller:CharacterController = GetComponent(CharacterController); var flags = controller.Move(moveDirection Time.deltaTime); grounded = (flags & CollisionFlags.Below) != 0; //^Here would be the "grounded only if colliding with layer X snippet"

Any help is greatly appreciated as always.

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 ScroodgeM · Jul 27, 2012 at 08:27 AM 0
Share

finally... player or enemy is an object that should not stop falling?

avatar image Xatoku · Jul 27, 2012 at 08:36 AM 0
Share

Yeah, if it were to touch the top of someone's head, then they should be told isFlying = true;

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ScroodgeM · Jul 27, 2012 at 08:27 AM

solution 1

make objects that should not collide in the same (different) layers, then using collision matrix disable collision between these two (with itself) layers.

http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

solution 2

if other object is enemy, so i think (depends on gameplay) player and enemy should not collide at all, enemy must have a trigger to just detect collision and make some events if it happened. trigger will not stop collider falling.

solution 3

make "OnCollisionEnter" method for character and just check other collider for it's ground flag. it can be just a Tag "Ground". so only CollisionEnter with object tagged "Ground" will set flag "Grounded" to 'true', then use this flag to fall or don't fall player down

http://docs.unity3d.com/Documentation/Components/Tags.html

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html

 void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Ground"))
        {
            isFlying = false;
        }
        //all other collidings should not set this flag to false, so only object tagged "Ground" can stop falling
    }
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 Xatoku · Jul 27, 2012 at 08:38 AM 0
Share

With Solution 3, how can I ask if the ground is beneath the character though? That's why I'm using .below in the first place.

avatar image ScroodgeM · Jul 27, 2012 at 08:50 AM 0
Share

I'm a little explained solution 3

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

Simple AI and Animation 2 Answers

Colliders not working with Character VS House 0 Answers

early collision above character controller 2 Answers

Character is not grounding. 2 Answers

Is there a way to create an overlap custom-shape? 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