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 /
avatar image
0
Question by Barbaroi · Dec 12, 2016 at 09:05 AM · physicsraycastraycasthittriggers

Cone 'Line of Sight' will not trigger on collision

alt text

I can't for the life of me figure this out.. Trying to get an enemy to see the player, or any objects really.. I made a child cone in the enemy to represent line of sight, this code here should trigger whenever that cone intersects with another object, but it just won't.

 public void checkSight()
     {
         if (alive)
         {
             RaycastHit rayHit;
             if (Physics.Linecast(eyes.position,player.transform.position, out rayHit))
             {
                 print("hit "+rayHit.collider.gameObject.name);
             }...


Thank you so much for your help.. been pulling my hair out over this.

screenshot-47.png (520.0 kB)
Comment
Add comment · Show 8
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 getyour411 · Dec 12, 2016 at 09:32 AM 1
Share

I haven't used Linecast not sure about your syntax but...your method is checkSight and most are uppercase first letter so just double check you are actually calling checkSight() and not CheckSight() ? And of course that "alive" is true.

avatar image Barbaroi getyour411 · Dec 12, 2016 at 04:52 PM 0
Share

Thanks for taking a moment to respond.. yes I've made sure that checkSight() is camelcase, and and set bool alive to true

avatar image getyour411 Barbaroi · Dec 12, 2016 at 06:03 PM 1
Share

Have you changed any of the Physics interaction matrix / layermasks / layers these things are on?

avatar image Barbaroi · Dec 12, 2016 at 07:55 PM 0
Share

@getyour411 I've set the enemy layer to ignore rayCast, I thought the cone itself was in the way or something, but no dice. I just tried messing with the interaction matrix, all the boxes were checked

avatar image getyour411 Barbaroi · Dec 12, 2016 at 08:56 PM 1
Share

Your syntax is fine, I tested it in an empty project. While doing so, I noticed this works a little different than I thought. Does Zombear have a character controller or collider on it (that eyes are maybe behind)?

Edit: It might be simplest to change this temporarily to a simple Raycast and query the hit

avatar image Barbaroi getyour411 · Dec 12, 2016 at 10:25 PM 0
Share

No, it doesn't have a character controller or colliders, except for the cone trigger. I tried doing Raycast ins$$anonymous$$d of Linecast

 public void checkSight()
     {
         if(alive)
         {
             Vector3 fwd = transform.TransformDirection(Vector3.forward);
             if (Physics.Raycast(eyes.position, fwd, 10))
             {
                 print("hit " + gameObject.name);....

didn't work. I'm pretty new to this so I don't understand enough to convey the problem very well, I really appreciate your time helping me with this, I think I need to move on to another project and try to come back to this when I have a better understanding of the engine and the language though. Seriously, thanks again

avatar image Owen-Reynolds · Dec 12, 2016 at 09:47 PM 0
Share

Wait -- the code is just a line. What do you mean by "cone" and "trigger"? You can perform a raycast, spherecast, etc... without needing any gameObjects to represent them.

Do you have an actual cone gameObject, set as a trigger, somewhere? If so, there's probably something wrong with that (and the code above is a red herring.)

avatar image Barbaroi Owen-Reynolds · Dec 12, 2016 at 11:56 PM 0
Share

Yes, what I did was I made a cone object, "eyes" as a child of my enemy object, and set it as a trigger. I have this script for the player, so that when the player enters the cone, it will trigger the checkSight function. Here is the code for player..

 public class player : $$anonymous$$onoBehaviour{
 
     public bool alive = true;
 
     void onTriggerEnter(Collider other)
     {
         if (other.gameObject.name == "eyes")
         {
             other.transform.parent.GetComponent<monster>().checkSight();
         }
     }
 }




0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Physics Raycast not working 1 Answer

Raycast hit.point differs from Ray direction [SOLVED] 1 Answer

Adding MaxDistance to RayCast Stops Raycast From working 0 Answers

RayCast(Ray ray, out RaycastHit hitInfo, float maxDistance, int layerMask) question 0 Answers

Issues with detecting collision with objects that have certain tags using Raycast 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