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 PaxForce · Mar 10, 2014 at 09:53 AM · collisioncolliderchildchildren

ignore child's collider

The MagicWand gameObject is the child of my Player gameObject. I increased the volume of the sphere collider of magicWand so it over-reaches the spherical collider of the Player. (It looks kinda like if PlayerGO was the nucleus of an atom and the collider of MagicWandGO was it's electron layer.)

The problem is, when I approach a PickUp item, it is picked up by the MagicWand's collider instead of Player's collider. Can this be fixed somehow?

This script is attached to MagicWand:

 public class MagicWand_P1_scr : MonoBehaviour {
     
     private bool _spellReady;
     public int _spellCharged;
     private bool _enemyWithinRange;
     public GameObject _spell;
     private Light _player2_light;
     
     // enum Spells{Shock, Ignite, AcidSpray};
     
     void Start () 
     {
         _spellReady = false;
         _enemyWithinRange = false;
         _player2_light = GameObject.FindWithTag ("Player_2").GetComponent<Light>();
     }
     
     // Update is called once per frame
     void Update ()
     {    
          Debug.Log("_enemyWithinRange " + _enemyWithinRange);
     }
     
     void OnTriggerEnter(Collider other)
          {
             if(other.name == "Player_2")
             {
                 _player2_light.enabled = true;
                 
                 _enemyWithinRange = true;
             }
          }    
     
     void OnTriggerExit(Collider other)
     {
         if(other.name == "Player_2")
         {
             _player2_light.enabled = false;
             
             _enemyWithinRange = false;
         }
     }
 
 }





This script is attached to Player:

 public class PlayerMover_P1_scr : MonoBehaviour {
     
     public float _movementSpeed;
     private int _health;
     
     MagicWand_P1_scr _magicWandController;
     
     // Use this for initialization
     void Start () {
         GameObject _magicWandObject = GameObject.FindWithTag ("magicWand_1");
             if (_magicWandObject != null)
             {
                 Debug.Log ("magic wand found");
             }
             _magicWandController = _magicWandObject.GetComponent<MagicWand_P1_scr>();
             if(_magicWandController != null)
             {
                 Debug.Log ("magicWandController found");
             }
         
         
         _movementSpeed = 7f;
         _health = 100;
         
     
     }
     
     void Update () 
     {
         if(Input.GetButtonDown ("Fire_P1"))
         {
             _magicWandController.CastSpell ();
         }
     }
     
     void FixedUpdate()
     {
         float _moveHorizontal = Input.GetAxis ("Horizontal_P1");
         float _moveVertical = Input.GetAxis ("Vertical_P1");
         
         Vector3 _movement = new Vector3(_moveHorizontal, 0.0f, _moveVertical);
         
         rigidbody.AddForce (_movement * _movementSpeed, ForceMode.Force);
     }
     
     
     void OnTriggerEnter(Collider other)
     {
         if(other.gameObject.name == "PickUp")
         {
             Debug.Log ("P1_col = " + other.gameObject.tag);
             
             Destroy (other.gameObject);
             
             if(other.gameObject.tag == "IGNITE_pu")
             {
                 xa._magicWand_1_SCRIPT.ChargeSpell("Ignite");
             }
             if(other.gameObject.tag == "SHOCK_pu")
             {
                 xa._magicWand_1_SCRIPT.ChargeSpell("Shock");
             }
             if(other.gameObject.tag == "ACID_pu")
             {
                 xa._magicWand_1_SCRIPT.ChargeSpell("Acid");
             }
         }
     }
 }




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
3
Best Answer

Answer by CodeElemental · Mar 10, 2014 at 10:11 AM

What you could try, is assign the magicwand collider to specific layer (different from the collider of the player), and regulate the collision in Player Preferences -> Physics (the checkboxes table).

For example :

Player in layer "Characters"

magicwand in "EquippedWeapons"

the pickup item "Items"

  • Uncheck the EquippedWeapons/Items checkbox.

Comment
Add comment · Show 4 · 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 PaxForce · Mar 10, 2014 at 10:34 AM 0
Share

I didn't even know something as "layers" existed in Unity. I'll give it a try. Is there any coding answer to this problem?

avatar image CodeElemental · Mar 10, 2014 at 11:00 AM 0
Share

Well , you could disable the magic wand collider on start( if your game design allows it)

  GameObject _magicWandObject = GameObject.FindWithTag ("magicWand_1");
 _magicWandObject.collider.enabled = false;


Or attach a collision-check script on the magic wand collider so it ignores collision with another ONE collider explicitly (which i assume is not what you want).

avatar image PaxForce · Mar 13, 2014 at 07:13 PM 0
Share

layers work.

avatar image DefogYap · Nov 28, 2018 at 06:20 AM 0
Share

THAN$$anonymous$$ YOU!

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

How do you detect which child collider was hit? 6 Answers

Collider isn't working ? 2 Answers

Detect collision point?? 1 Answer

Trying to detect multiple points on a single collider 1 Answer

accessing all of a colliders parents children 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