playMaker

Author Topic: How to get an object's linecast to ignore itself?  (Read 3531 times)

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
How to get an object's linecast to ignore itself?
« on: March 31, 2016, 05:31:50 PM »
I have an object testing for line of sight to another object and they both need to be on the same layer, so layer-masking doesn't seem to be a solution. The colliders of both objects are not set to IsTrigger, so the Ecosystem action to linecast ignoring triggers doesn't seem to be a solution either. At the moment, the object is returning itself as the hit object, regardless. This must be a common problem. Any help would be greatly appreciated.

(Aside: I can't understand why it isn't a default for an object to ignore its own collider - when would it be useful to test if an object is in its own line of sight? Surely either it always is or it never is, depending how you work it.)

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: How to get an object's linecast to ignore itself?
« Reply #1 on: March 31, 2016, 06:09:41 PM »
I think you would usually set it to a different layer but if you can't there a few options-

If it registers as a hit- use compare game object to compare the hit object with the owner and if its true use a "next frame" event and return to the state firing the linecast-

If you can't do that because you only want it to send a hit event when a valid hit occurs- you can modify the line cast action to make it ignore hitting its own game object- I made a "trigger event ignore game object" action to do just that but for trigger events-

I modified the original line cast action to make the one with "ignore triggers" I'll have a look and see if I can add the "ignore game object" option as well-

Update:

Looking at the code with my noob skills I don't see a way to avoid registering a hit even if the hit is ignored- it would be doing the same thing as adding the compare game object and I'm afraid the action would just get stuck in a loop hitting itself
« Last Edit: March 31, 2016, 06:17:42 PM by mdotstrange »
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Re: How to get an object's linecast to ignore itself?
« Reply #2 on: April 03, 2016, 10:54:09 AM »
Thanks very much for your help. It's very useful to know it's a dead-end and I'll have to find some other way. Still mystified about why Unity doesn't ignore self by default though.