- Home /
How to make some raycasts ignore a layer and others not?
I'm making a chess-like game, which uses two types of raycast.
Type one is for clicking. When the mouse clicks, it casts a ray from the mouse position to the game world, and gets the object clicked on.
Type two is for detecting the board state. To check what is in a tile position, a raycast is positioned above the tile and fired down, and returns what object it hits.
I want type one rays to ignore the pieces, so you click through to the tile its on top of, without preventing type two from seeing pieces.
How do i tell one ray "Ignore the pieces" and another "Don't ignore the pieces"?
Thats done it :D You had your types backwards in your answer, but the important bit was spot on :D Thanks man! $$anonymous$$ake it an answer and i'll thumb it
Answer by Scribe · Apr 06, 2014 at 11:59 AM
Put your chess pieces on the ignoreraycast layer and do your type 2 raycast as you would normally. Then for your type 1 raycast pass it the layerMask field of its constructor:
static bool Raycast(Vector3 origin, Vector3 direction, float distance = Mathf.Infinity, int layerMask = DefaultRaycastLayers);
where you should give it Physics.AllLayers
as the argument for layerMask.
I haven't tested this at all hence why im adding it as a comment
Scribe
wooh, just found out i have karma enough to convert my comments to answers :o
Glad I could help anyway! :)
Your answer
Follow this Question
Related Questions
Ignoring an object (using raycast with layers) is not working 1 Answer
Set transform layer 1 Answer
Raycast ignoring layers that it should not 2 Answers
Can't Ignore a Layer when raycat 0 Answers
Raycast doesnt hit ground 2 Answers