playMaker

Author Topic: Ray Casting Not Working  (Read 3605 times)

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Ray Casting Not Working
« on: February 09, 2016, 03:07:10 PM »
Hello,

I have been following the AI tutorials BadSeedGames has done. The only difference is that I am not using 3D objects but 2D ones. So I am using the equivalent 2D actions in everything.
However when I get to test my game, it doesn't detect seeing/hitting the player even though nothing is between it and the player. I also made sure that they are on the same "Z" value so as not to test on different Z levels.

Here is my setup below:





Thanks in advance for your help!

replikant

  • Playmaker Newbie
  • *
  • Posts: 42
Re: Ray Casting Not Working
« Reply #1 on: February 10, 2016, 03:25:30 AM »
Are you using the raycast2d action?

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: Ray Casting Not Working
« Reply #2 on: February 10, 2016, 03:28:03 AM »
Yes definitely; I always use the 2D action when following tutorials.

replikant

  • Playmaker Newbie
  • *
  • Posts: 42
Re: Ray Casting Not Working
« Reply #3 on: February 10, 2016, 01:23:41 PM »
are you using 2dcollider too?

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: Ray Casting Not Working
« Reply #4 on: February 10, 2016, 01:25:55 PM »
Yes, indeed the player has a 2D collider.

That actually got me thinking and I found out it is a mistake from my end. One of the objects sending the ray cast had a too big collider that it covered the ray cast. Which brings a question, how can I put a collider on a raycaster object without interferring with the raycaster?

However, there is another problem that surfaced. The detection doesn't still happen right away; it happens after moving around the object for a while.

So for example, I have raycaster and target. If there are no objects between raycaster and target, the raycaster doesn't detect the target. Even if I left it there for a few minutes. However if I move the target around, the raycaster picks it up after a while (not right away either).

If I put an object between the target and the raycaster it still doesn't detect the obstacle at all. Even though I have in the setup two cases where one detects the obstacle and puts in the debug window that it sees the target and the other puts out that it sees the obstacle.

Any idea how to resolve this? It is pretty weird really.
« Last Edit: February 10, 2016, 01:40:40 PM by Vallar »

replikant

  • Playmaker Newbie
  • *
  • Posts: 42
Re: Ray Casting Not Working
« Reply #5 on: February 10, 2016, 01:59:02 PM »
try to setup layers for the raycaster

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: Ray Casting Not Working
« Reply #6 on: February 11, 2016, 02:55:29 AM »
Can you elaborate, please?

replikant

  • Playmaker Newbie
  • *
  • Posts: 42
Re: Ray Casting Not Working
« Reply #7 on: February 11, 2016, 03:37:12 AM »
 the raycaster have a layer option. use them to single out what they are allowed to see. check out the documentation.

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: Ray Casting Not Working
« Reply #8 on: February 11, 2016, 04:11:52 AM »
I completely understand and I think that would resolve the collider problem, but the rest of the problems I am not sure it would affect them.

replikant

  • Playmaker Newbie
  • *
  • Posts: 42
Re: Ray Casting Not Working
« Reply #9 on: February 11, 2016, 08:06:27 PM »
it will resolve all the problems, try it out

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: Ray Casting Not Working
« Reply #10 on: February 11, 2016, 08:44:33 PM »
Alright, I'll give it a go. Thank you very much!