Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Vallar on February 09, 2016, 03:07:10 PM

Title: Ray Casting Not Working
Post by: Vallar 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:

(http://i.imgur.com/VoJmLTj.png?1)

(http://i.imgur.com/pvOjAa5.png?1)

Thanks in advance for your help!
Title: Re: Ray Casting Not Working
Post by: replikant on February 10, 2016, 03:25:30 AM
Are you using the raycast2d action?
Title: Re: Ray Casting Not Working
Post by: Vallar on February 10, 2016, 03:28:03 AM
Yes definitely; I always use the 2D action when following tutorials.
Title: Re: Ray Casting Not Working
Post by: replikant on February 10, 2016, 01:23:41 PM
are you using 2dcollider too?
Title: Re: Ray Casting Not Working
Post by: Vallar 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.
Title: Re: Ray Casting Not Working
Post by: replikant on February 10, 2016, 01:59:02 PM
try to setup layers for the raycaster
Title: Re: Ray Casting Not Working
Post by: Vallar on February 11, 2016, 02:55:29 AM
Can you elaborate, please?
Title: Re: Ray Casting Not Working
Post by: replikant 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.
Title: Re: Ray Casting Not Working
Post by: Vallar 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.
Title: Re: Ray Casting Not Working
Post by: replikant on February 11, 2016, 08:06:27 PM
it will resolve all the problems, try it out
Title: Re: Ray Casting Not Working
Post by: Vallar on February 11, 2016, 08:44:33 PM
Alright, I'll give it a go. Thank you very much!