• 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 River-Ofarrows · May 08, 2016 at 06:36 AM · javascriptraycastcolliderwallstealth

raycast going through walls

a have a simple scene that has an object and a wall and a player. i am trying to have the object (a camera) see the player if they he or she is in the cameras line of sight. but the problem is that my raycast casts through a wall that the player should be able to hide behind. her is my script. (the collider of the sphere is a size 20 radius so it penetrates the wall) p.s. i am a big noob to unity

 #pragma strict
 
 var fieldOfViewAngle : float = 100.0;
 var col : SphereCollider;
 var hit : RaycastHit;
 var vectr3 : Vector3;
 
 function OnTriggerStay (other : Collider) {
     var fwd = transform.TransformDirection(Vector3.forward);
     var direction : Vector3 = other.transform.position - transform.position;
     if(other.CompareTag ("noticeableThing")){
         var vectorFromEnemyToPlayer : Vector3 = other.transform.position - transform.position;
         var forwardVector = transform.forward;
         var angle : float = Vector3.Angle(vectorFromEnemyToPlayer, forwardVector);
         if(angle < fieldOfViewAngle * 0.5f) {
                 if(Physics.Raycast(transform.position + transform.up, direction.normalized, hit, col.radius)){
                     if (hit.collider.tag == "noticableThing");
                     print("HA");
             }
         }
     }
 }
 
 function Awake () {
     col = GetComponent(SphereCollider);
 }
Comment
Add comment · Show 5
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 Oribow · May 08, 2016 at 10:19 AM 0
Share

Please use code tags and format your question properly. It's a matter of respect by showing that you are willing to put the same effort as we into your questions.

avatar image River-Ofarrows · May 08, 2016 at 07:28 PM 0
Share

well I thought i was doing it right. what did I fail at?

avatar image incorrect River-Ofarrows · May 08, 2016 at 07:41 PM 0
Share

$$anonymous$$arkdown Syntax

avatar image River-Ofarrows incorrect · May 08, 2016 at 10:07 PM 0
Share

so what is it I need 2 fix? just take out "hashtag pragma strict"?

avatar image River-Ofarrows · May 09, 2016 at 03:07 AM 0
Share

i did. ... what did i miss?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Check if position is inside a collider 5 Answers

Object moving fast keeps "climbing" walls 1 Answer

Can you help me with ''yield WaitForSeconds''? 1 Answer

How can I select 2 different objects using RayCastHit? 0 Answers

Make raycast ignore hitbox? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges