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 Nicolas-Liatti · Jan 04, 2014 at 02:38 PM · mesh collider

Mesh Collider

Hi,

I'm getting crazy with a mesh collider... I need to check wether an object is inside the cone vision or not. I use OnTriggerEnter and OnTriggerExit for this. The "funny" stuff is that if the player goes in the vision cone by the bottom of the pyramid, I have both OnTriggerEnter and OnTriggerExit which fires.

I tried to use OnTriggerStay, and it's even weirder: OnTriggerStay works only when I go outside of the mesh.

I tried to check the concave option, but the only thing it does is that OnTriggerExit is never called then...

My player character has a Character Controller and a Rigidbody, and the pyramid has a Rigidbody as well.

Any idea how I can make it work? (with a Box Collider it works just fine... but I need a cone/pyramid :( )

alt text

capture d'écran 2014-01-04 22.29.58.png (396.9 kB)
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
1
Best Answer

Answer by Flue · Jan 04, 2014 at 04:19 PM

I had the same problem once. The mesh colliders are a little weird. At least i couldnt make it work.

You dont need a mesh for enemy sight though. You could through script instead just check if player is within range, if he is within a certain angle in front of the enemy, and if you can raycast to him. If you want, instead of checking if he is within range, you could change your view cone to a box collider, and just make sure "not to see the player" if he is not within the angles.

 var fieldOfViewAngle : float = 150f; // the angle of sight, 150 degrees
 var Dist : float = 30.0; // the max distance of sight
     
 var direction : Vector3 = Player.position - EnemyEyes.position; // Get the direction between the player and the eyes of the enemy
 var angle : float = Vector3.Angle(direction, Enemy.forward);
         
 // if player is within the right angle
 if(angle < fieldOfViewAngle * 0.5f)
 {
    var hit : RaycastHit;
    
    // Draw a ray if you want
    Debug.DrawRay(EnemyEyes.position, direction);
     
    // make a raycast. Using Dist also makes sure player is within range.        
    if(Physics.Raycast(EyeSpot.position, direction, hit, Dist)) // You may also want to add a layermask to this raycast if you have seethrough objects
    {
        // If theres nothing between the enemy and the player
        if(hit.collider.transform == Player.transform)
        {
             // Enemy can see player
                     
     }
 }
        
Comment
Add comment · Show 1 · 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 Nicolas-Liatti · Jan 04, 2014 at 11:06 PM 0
Share

The solution of the Box Collider with the angle to check works great! Thanks!

Another solution I was thinking about was to check if the player is within the triangle of the vision, I think it would work as well.

avatar image
0

Answer by Owen Burk · Jan 04, 2014 at 03:18 PM

You need to check what is entering the collider.

 function OnTriggerEnter(theCollider : Colldier)
 {
      if(theColldier.tag != "Player")
      {
            //Whatever you want
      }
 
 }

You will have to make the tag for the player in the inspector, add the same if statement to the OnTriggerExit.

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 Nicolas-Liatti · Jan 04, 2014 at 03:26 PM

Hi,

I already have that.

In fact, after digging a bit more: when my Player is not moving, OnTriggerEnter works but not OnTriggerExit on certain sides of the pyramid. It works on some of them, but not on others. When the Player is moving however OnTriggerExit works on every sides...

Any idea?

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

20 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

Related Questions

Mesh collider and Terrain collider 0 Answers

Default Mesh colliders are not working 1 Answer

Mesh Collider to a character and the maze? 3 Answers

How do i find the top of a mesh? 3 Answers

Procedural Generated mesh collider creates invisible walls after the first iteration 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