playMaker

Author Topic: Raycast - How to shine light into eyes but not head [SOLVED]  (Read 882 times)

ghostLA

  • Playmaker Newbie
  • *
  • Posts: 2
I am trying to build an enemy that does an event only if the player shines light into its eyes. So far, the raycast does not stop from any collider, so it triggers from any direction... even from behind the enemy.

In the image attachment, if the checkmark part was hit with a raycast, then the event would appear. But ONLY from the front or front side.


I have tried all sorts of combinations with Game Object Compare Tag and Layers. Got a hunch that the answer might be somewhere with those two.
« Last Edit: July 15, 2020, 12:24:46 AM by ghostLA »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
    • jinxtergames
Re: Raycast - How to shine light into eyes but not head
« Reply #1 on: July 14, 2020, 01:47:24 PM »
Hi.
Maybe you could set a empty object on the front of the head and set a box collider that sticks out very little on the front.
it can have the same layer but a different Tag.

On raycast hit, store the object hit.
then check tag if it is the front box or the head.

Also maybe this unity Thread might give you some ideas, especially the post from Ultimationz

https://forum.unity.com/threads/detect-the-side-of-physics-raycast-hit.121697/

ghostLA

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Raycast - How to shine light into eyes but not head
« Reply #2 on: July 15, 2020, 12:05:29 AM »
@djaydino Your advice worked!  8) I think my big oopsy was I wasn't storing the object hit from raycast.

The rest of this post is for anyone who gets here later from a search:


Head (object)
Tag: Enemy
Layer: Face Raycast

  Face (object)
  Tag: Face
  Layer: Face Raycast


RAYCAST
From Game Object: Use Owner
Direction: X 0, Y 0, Z 1
Space: Self
Distance: 7

Result
Hit Event: ObjectWasHit
Store Hit Object: ObjThatWasHit 

Filter
Repeat Interval: 1
Layer Mask: 1
   Element 0: Face Raycast


GAME OBJECT COMPARE TAG
Game Object: ObjThatWasHit
Tag: Face
True Event: FaceHit
False Event: FaceNotHit