playMaker

Author Topic: Raycasting for enemy vision [SOLVED]  (Read 5247 times)

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Raycasting for enemy vision [SOLVED]
« on: November 08, 2011, 01:03:26 AM »
I'm trying to get enemies to have a field of view for seeing the player. I thought I'd be able to cast a ray from the enemy to the player and if the player isn't occluded and is within some numbers... (hadn't got it all figured out yet).

But then I found that raycasting doesn't have that option (object to object). So now I'm a bit lost.

Is raycasting with Playmaker a way to do this at all? Because, of course, it's not a single ray out in front of the enemy, it has to be more like a cone of vision. Is there another action that would do this?
« Last Edit: November 08, 2011, 03:43:50 AM by FractalCore »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Raycasting for enemy vision
« Reply #1 on: November 08, 2011, 02:16:42 AM »
Hi,

You can cast a ray at a specific direction and then test if the player is indeed not occluded and if within a certain range.

one way all doable with playmaker ( amongst many other of course):

 Have a look out fsm on a gameObject attached to the enemy to always look at the player, cast a ray from this game object, because it is always looking at the player, you then test if the first hit collider is part of the player, and if yes then test the range.

if you need a constrained field of view, simply constraint your look out somehow to only work when the angle between your enemy forward direction and the look out gameobject  is less than a certain angle. then if the enemy is not facing the right way, the system will not even bother casting a ray. Do that also with the distance, compute the distance between your enemy and the player, if it's too far, don't even bother doing a look out and even less a ray cast.

 Does that make sense?

 Bye,

 Jean

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Raycasting for enemy vision
« Reply #2 on: November 08, 2011, 03:43:09 AM »
Awesome, for some reason I forgot about using a different action to look at the player the whole time, and raycast from an object that's a child of that. Works perfectly.

I still need to restrict the vision, but at least I can see the First Hit GameObject variable changing to whatever my character walks behind.

Thanks.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Raycasting for enemy vision [SOLVED]
« Reply #3 on: November 08, 2011, 08:02:56 AM »
Hi,

 I am glad you got it working.

 as far as restricting "vision", use tags on models or something, create a ray cast of a specific length ( so that your robot can not see too far), and then go through the hit list and check for tags to know if this is a occluder or not.

 Bye,

 Jean