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 /
avatar image
0
Question by AlbertoForlenza · May 31, 2018 at 10:01 AM · raycastcolliderignorethird-person-shooter

Raycast with doubleCollider

Hi,sorry for my english. I am building a third person shooter. On enemy target i have a double collider, Capsule collider for the enemy mesh and a sphere collider for the aggrozone(on the same object(enemy)). When i shoot of course my raycast hit the aggrozone and decrease the enemy's life. How can ignore the first collider?Please help me, i am going crazy. Ray ray=Camera.main.ViewportPointToRay(Vector3.one*0.5f); Debug.DrawRay (ray.origin, ray.direction * 100, Color.red, 2f); RaycastHit hitinfo;

     if (Physics.Raycast (ray, out hitinfo, 100)) {
 
     var health = hitinfo.collider.GetComponent<health> ();
         if (health != null) {
             health.takedamage (damage);    
             print(hitinfo.collider.gameObject.name);
     } 
        else print(hitinfo.collider.gameObject.name);
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

3 Replies

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

Answer by Captain_Pineapple · May 31, 2018 at 10:43 AM

Hey there,

shouldn't an aggrozone be a trigger instead of a collider? Then a normal raycast should ignore it either way. If this does not help or is not an option let me know. There are some other ways that might be working for your situation.

Comment
Add comment · Show 3 · 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 AlbertoForlenza · May 31, 2018 at 10:55 AM 0
Share

Thanks for reply. This is my settings on enemy player. I am a beginner on Unity. alt text

Here my aggro code: public class aggrodetection : $$anonymous$$onoBehaviour {

     private health myhealth;
 
 
     public event Action<Transform> onaggro= delegate {};
 
     private void OnTriggerEnter(Collider other){
 
         var player = other.GetComponent<playermovement> ();
         if (player != null) {
         
             onaggro (player.transform);
             Debug.Log ("Aggrod");
         }
     }
 }


screenshot-20.png (30.1 kB)
avatar image AlbertoForlenza · May 31, 2018 at 12:47 PM 0
Share

U were right! A normal raycast should ignore trigger collider if u go in : Edit->ProjectSettings->Physics->Uncheck m_Querieshittrigger. Thanks a lot, now works!

avatar image Captain_Pineapple AlbertoForlenza · May 31, 2018 at 01:58 PM 0
Share

Hey,

yeah my bad on that one. I forgot that you have the control to enable or disable this for your whole project and that the default value is enabled.

You can ofc tell a specific raycast to hit triggers or not via the QueryTriggerInteraction enum as parameter for the Physics.Raycast.

avatar image
0

Answer by AlbertoForlenza · May 31, 2018 at 11:30 AM

I just wanna figure it out. I can poste everything , scripts etc.

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 Axtrainz · May 31, 2018 at 12:40 PM

@AlbertoForlenza Separate aggro-zone collision on a child object with different tag/layer, Also make the Ray Mask to only hit the enemy tag or layer, not all.

you can check something like this:

 if(hitinfo.collider.gameobject.tag == "Enemy")
 {
  takedamage();
 }
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

133 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make raycast ignore some objects. 2 Answers

Raycasts ignoring colliders based on Collider Name 2 Answers

Character Controller can pass through Collider 1 Answer

Ignoring Layer for OnMouseEnter/OnMouseExit 0 Answers

Raycast not working on object without gravity 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