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 Voridian · Nov 08, 2014 at 11:50 AM · c#raycasttrigger

How can i make only some Raycasts hit triggers

I'm sure there is an easy fix for this but i have no idea what it is, basically i use Raycasting for picking up items using triggers, and a separate Raycast for telling my game where to shoot.

The problem is that when Instantiating a decal, the shooter raycast hits the triggers and the decal hovers over some objects (sorry for the bad explanation, see picture below). Can i either make some Raycasts ignore triggers but not others or toggle the 'Raycasts hit trigger' option in physics settings via C#.

Thanks for any help.

Screenshot: http://s10.postimg.org/uvrmu86rt/Trigger_Issue.png

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by 767_2 · Nov 08, 2014 at 12:52 PM

you should make a layerMask and use it in your raycast like below , make a layer for objects you want to use them to trigger and say to use that layer on your raycast

(if new layer is layer 8)

 int layerMask = 1 << 8;
 
     if (Physics.Raycast (transform.position, Vector3.forward, Mathf.Infinity, layerMask)


Comment
Add comment · Show 4 · 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 Voridian · Nov 08, 2014 at 03:56 PM 0
Share

I$$anonymous$$PORTANT EDIT: I looked into Layer$$anonymous$$asks and i dont know how it will help because the triggers are componants of GameObject.

Thanks for the answer, I have never used a layer mask before, would you be able to explain that a bit more thoroughly? do i put the layer mask on the my shooter raycast or my item raycast? and do i need to change the layers collision settings at all? Here is my Shooter raycast if it helps, the itempickup is much longer but similar:

         RaycastHit hit;
         Ray shootRay = new Ray(transform.position, transform.forward);
         Debug.DrawRay(transform.position, transform.forward, Color.red);
         if(Physics.Raycast(shootRay, out hit) && Input.GetButtonDown("Fire1") && canFire && ammo > 0 && shooterWeapon && !inventoryOpen){
             canFire = false;
             ammo -= 1;
             var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
             GameObject decal1;
             if(hit.transform.tag != "Decal"){
             decal1 = Instantiate(decal, hit.point, hitRotation) as GameObject;
             decal1.transform.parent = hit.transform;
             }
             print ("BANG");
             StartCoroutine(slightDelay(rof));
         }

avatar image 767_2 · Nov 08, 2014 at 04:23 PM 0
Share

put all objects that you want to be in collison in your layermask and it doesnt got do anything with collision mask (look here)

avatar image 767_2 · Nov 08, 2014 at 04:35 PM 0
Share

what do you mean how it will help

avatar image Voridian · Nov 09, 2014 at 02:26 PM 0
Share

sorry for the late reply, i dont know how it will help because i use those triggers for raycasting on another script, if i make a layer mask i wont be able to trigger them at all correct?

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

27 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

Related Questions

Moving trigger collider and raycast doesnt detect anything 0 Answers

How to Find Owner of a Trigger? 1 Answer

Multiple Cars not working 1 Answer

Help With Player Decrease Enemy Health!,Need Help with Character 1 Answer

Distribute terrain in zones 3 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