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
1
Question by YeOldeSnake 1 · Aug 30, 2010 at 09:09 AM · triggermasklayerlinecast

Linecast Layer Mask Declaration Problem

var awareness:float; var aiOwner:GameObject; function OnTriggerStay(other : Collider) { if(other.gameObject.tag =="Player"&&!Physics.Linecast (aiOwner.transform.position,other.transform.position,2)){

other.GetComponent("DetectionScript").NoticedPlaya(awareness);

} }

My scene looks like this

O=======

O is a waypointed AI and ======= are certain triggers for visibility , havign the code above.aiOwner of each trigger is set to the "O"Waypointed AI gameobject The code above uses linecast with the layer mask being 2 for IgnoreRaycast which the triggers have as their layer. The problem is that the linecast doesnt work and its being negative , even when a wall is between the player and the AI , without having set 2 as the linecast's ignore layer, the linecast from the AI hits the triggers and always returns true. Any ideas on how to solve this?

EDIT: OBVIOUSLY im declaring the layer falsely , can someone give me a proper example of how to do it properly?

EDIT 2: after declaring the layer with a valid way , still the problem persists , also , the position where the game thinks aiOwner is isnt at the relative position of the capsule to its parent , it appears its completely random ,its at position

X=30611.73
Y=-6522.702
Z=11684.97

http://img715.imageshack.us/img715/3140/linecastproblem.png

Comment
Add comment · Show 3
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 · Aug 31, 2010 at 01:05 PM 3
Share

I might be the only one, but seeing "URGENT" is generally a deterrent. Everyone thinks their question is "urgent" or "important", else they wouldn't usually be asking.

avatar image YeOldeSnake 1 · Aug 31, 2010 at 04:14 PM 1
Share

Basically it affects one of my game's basic features/functions so it would be best if it would be solved immediately

avatar image BerggreenDK · Dec 05, 2010 at 08:45 AM 0
Share

I never answer questions for free if they are "URGENT". If they are that important, people should pay for answers. Thats whats consulting agencies are for.

2 Replies

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

Answer by YeOldeSnake 1 · Sep 01, 2010 at 10:17 AM

Got it fixed

var layerMask : int = 1 << 2; layerMask=~layerMask; var awareness:float; //var aiOwner:Transform; var hit:RaycastHit; function OnTriggerStay(other : Collider) {

if(other.gameObject.tag =="Player" && !Physics.Linecast (other.transform.position,transform.parent.position, layerMask)){ other.GetComponent("DetectionScript").NoticedPlaya(awareness); Debug.DrawRay (transform.parent.position* 10,other.transform.position, Color.green);

} }

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
1

Answer by burnumd · Aug 30, 2010 at 06:48 PM

You need to use a LayerMask. I imagine what you're looking for is

if(other.gameObject.tag =="Player" && !Physics.Linecast (aiOwner.transform.position, other.transform.position, LayerMask (2)))

If you want to do the math yourself, there are instructions here. In that case you'd use

var layerMask : int = 1 << 2;
if(other.gameObject.tag =="Player" && !Physics.Linecast (aiOwner.transform.position, other.transform.position, layerMask))
Comment
Add comment · Show 2 · 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 YeOldeSnake 1 · Aug 31, 2010 at 09:21 AM 1
Share

hmmm , thats what i had done shortly after i posted the question here , yet to no avail , if i draw a debug ray with that code THIS happens

http://img715.imageshack.us/img715/3140/linecastproblem.png

avatar image YeOldeSnake 1 · Aug 31, 2010 at 09:33 AM 0
Share

updated the OP with the new info

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

No one has followed this question yet.

Related Questions

Can't Make Raycast Ignore a Layer 3 Answers

Animator with mask problem 0 Answers

Override avatar mask in layer 1 Answer

Is there a way for a trigger to ignore objects on a certain layer? 1 Answer

Computational cost of using many Triggers (occlusion culling) 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