Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Jun 03, 2016 at 11:12 AM by Hellium for the following reason:

Question already answered.

Use Layer-based Collision detection

http://docs.unity3d.com/Manual/LayerBasedCollision.html

avatar image
0
Question by McVitty · Jun 03, 2016 at 06:17 AM · collisiondetection

Selective Collision Detection

Hi everyone.

I'm trying to implement a projectile magic system, and at the moment what I have is a system that destroys the spell when it collides with anything, using "OnTriggerEnter".

The problem is that I also have an Elder Scrolls style crosshair set up, which is a long capsule collider that extends out from the centre of the screen (the idea being that if it collides with an item, like a gold coin, I can pick up the coin). The spell will destroy itself immediately after being instantiated because it detects the crosshair collider.

I need some sort of way of making the OnTriggerEnter check for every object other than the crosshair. I'm using C# and I'm not thoroughly experienced with it, but there must be some sort of "Ignore Tag" system or something.

I tried a "StopCoroutine" line when it detects the crosshair, but this cancels out its destruction upon collision with other objects if it's still touching the crosshair. So if I stand up against a wall and shoot the spell, the spell would go through the wall because its destruction would be cancelled out due to still touching the crosshair.

Thank you for your help!

 using UnityEngine;
 using System.Collections;
 
 public class ProjectileMagic : MonoBehaviour {
 
     public int damage;
     public float speed;
     private EnemyScript targetScript;
 
     void Start () {
         StartCoroutine ("SpellLife");
     }
     
     void Update () {
         transform.position += transform.forward * Time.deltaTime * speed;
     }
 
     void OnTriggerEnter (Collider other)
     {
         StartCoroutine ("DestroySelf");

         if (other.gameObject.CompareTag ("Enemy")) {
             targetScript = other.gameObject.GetComponent<EnemyScript> ();
             targetScript.healthPoints = targetScript.healthPoints - damage;
             StartCoroutine ("DestroySelf");
         }
     }
 
     IEnumerator DestroySelf () {
         yield return new WaitForSeconds (0);
         Destroy (gameObject);
     }
 
     IEnumerator SpellLife () {
         yield return new WaitForSeconds (20);
         Destroy (gameObject);
     }
 }

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 allenallenallen · Jun 03, 2016 at 07:36 AM 0
Share

You want to pick up a coin you are looking at? Use raycasts, not a huge collider. This would solve all your problems.

avatar image McVitty allenallenallen · Jun 03, 2016 at 11:39 PM 0
Share

Thanks! I'll look into it.

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by tanoshimi · Jun 03, 2016 at 08:01 AM

As @allenallenallen commented, you'd be better off raycasting than using a collider for your crosshair. But, either way, you implement selective collision detection using layers, as explained at http://docs.unity3d.com/Manual/LayerBasedCollision.html

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 JVince · Jun 03, 2016 at 11:10 AM

If you just want check collision on trigger, I think this is what you want. And if you wanna pick up item, I agree with tanoshimi Reply and allenallenallen commented.

 int igObj=0;
 void OnTriggerEnter(Collider col){
        if(col.compareTag("ignoreItem")){
              igObj++;
        }
        if (igObj != 0){
              //Some Amazing Code
        }
     }
     
     void OnTriggerExit(Collider col){
        if(col.compareTag("ignoreItem")){
              igObj--;
        }
        //Some amazing Code
     }
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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can I detect a collision between two triggers on other objects 1 Answer

My collision is not detecting 1 Answer

Best way to do Collision detection when you have multiple enemies/allies around you 0 Answers

Checking for collisions 1 Answer

How to detect a collision. Coming back to using Unity after taking a break for a few years. 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