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 basphi · Jun 04, 2014 at 06:41 PM · 2dcollidermesh

How Can I switch between 2 colliders in my 2D Game?

Hey Guys!

I'm almost finish with my first 2D-Platformer. The last thing I want to do is to bend down my character that I don't collide with birds. I implemented the Graphics and can call it by pressing the down button on my keyboard. The problem is: The bird applies damage on me even if I'm bend down because I have a mesh collider on my player which touches the box collider of the bird.

I thought I could fix this if I make an if-request: if my player is bend down->Turn off my mesh collider and activate a new box collider, which is smaller, that other animals on the ground can also apply damage to me.

The problem is I have really no idea how to do this.

The control for my character is in the script "PlayerController" and the apply damage function is in may "WaypointWalker" script. It looks like this:

 protected virtual void ApplyDamage (int damage)
     {
         if(!isHit)
         {
             isHit = true;
             currentHealth -= damage;
             AudioSource.PlayClipAtPoint(hitSound,transform.position,1);
 
             if(currentHealth <= 0)
             {
                 currentHealth = 0;
                 Die();
             }
             else
             {
                 StartCoroutine (DamageEffect ());
             }
         }

Does anyone of you know how I can solve this problem? You would make me very happy!!!

Sarah :)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MikeNewall · Jun 04, 2014 at 07:34 PM

Create two empty game objects that are parented to your character, one with the mesh collider attached and one with the box collider. Name them appropriately. You can search for these objects and disable/enable them when you crouch/stand.

     GameObject standCollider;
     GameObject crouchCollider;
 
     void Start(){
         standCollider = transform.FindChild("Stand Collider").gameObject;
         crouchCollider = transform.FindChild("Crouch Collider").gameObject;
         crouchCollider.SetActive(false);
     }
 
     void Update () {
         
         if(Input.GetKeyDown(KeyCode.DownArrow)){
             standCollider.SetActive(false);
             crouchCollider.SetActive(true);
         }
 
         if(Input.GetKeyUp(KeyCode.DownArrow)){
             crouchCollider.SetActive(false);
             standCollider.SetActive(true);
         }
     }
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

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

21 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

Related Questions

Mesh collider cost 1 Answer

Turn an objects mesh renderer on upon collision. 1 Answer

Tile-based approach in Unity 1 Answer

3d collider mesh to 2d collider mesh 0 Answers

How to make 3D colliders on sprites? 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