Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Adam Z on March 28, 2014, 10:34:00 AM

Title: Best way to use raycasts for line-of-sight?
Post by: Adam Z on March 28, 2014, 10:34:00 AM
Is it possible to send out multiple raycasts when setting up line-of-sight for an AI? (See example) I'm trying to develop a "cone" of vision, so that way targets can either be crouching and/or atop of buildings, etc.

If someone has another solution, I would love to hear it!

Thanks.
Title: Re: Best way to use raycasts for line-of-sight?
Post by: Adam Z on March 28, 2014, 10:58:26 AM
I could use game objects and set them up in the correct positions, sending out rays from those, but maybe there's an easier way?
Title: Re: Best way to use raycasts for line-of-sight?
Post by: sebaslive on March 28, 2014, 12:10:13 PM
taken from the unity answers:

You want to calculate the direction between the enemy and the player, get the forward vector of the enemy, and then use Vector3.Angle to calculate the angle.

Then you can check if the angle is less than whatever angle you want to be the enemy's field of vision (eg: a 20 degree cone, for instance), and if it is, then the player is in that enemy's field of vision.
----
so in playmaker terms, use the vector3 operator, set up two vector 3 variables and set it to Angle. Get the players vector3 and if it is in that range you use "You can Store Magnitude in Get Axis Vector and use Float Compare on that..."

and that is another way to do it!

---

I also found this vector3 compare that Julius created. http://hutonggames.com/playmakerforum/index.php?topic=3058.0

Title: Re: Best way to use raycasts for line-of-sight?
Post by: Adam Z on March 28, 2014, 12:16:33 PM
taken from the unity answers:

You want to calculate the direction between the enemy and the player, get the forward vector of the enemy, and then use Vector3.Angle to calculate the angle.

Then you can check if the angle is less than whatever angle you want to be the enemy's field of vision (eg: a 20 degree cone, for instance), and if it is, then the player is in that enemy's field of vision.
----
so in playmaker terms, use the vector3 operator, set up two vector 3 variables and set it to Angle. Get the players vector3 and if it is in that range you use "You can Store Magnitude in Get Axis Vector and use Float Compare on that..."

and that is another way to do it!

---

I also found this vector3 compare that Julius created. http://hutonggames.com/playmakerforum/index.php?topic=3058.0

Thanks! How does this take into account obstacles blocking your view? With Raycasting the ray stops on the closest object.
Title: Re: Best way to use raycasts for line-of-sight?
Post by: sebaslive on March 28, 2014, 12:24:24 PM
hmm, that is a good point. have you messed around with the pathfinder package? http://hutonggames.com/playmakerforum/index.php?topic=2540.0

or indieRAIN?
---
Title: Re: Best way to use raycasts for line-of-sight?
Post by: Adam Z on March 28, 2014, 12:29:48 PM
Thanks! That will definitely help with pathfinding.
Title: Re: Best way to use raycasts for line-of-sight?
Post by: Uttpd on March 28, 2014, 12:31:25 PM
taken from the unity answers:

You want to calculate the direction between the enemy and the player, get the forward vector of the enemy, and then use Vector3.Angle to calculate the angle.

Then you can check if the angle is less than whatever angle you want to be the enemy's field of vision (eg: a 20 degree cone, for instance), and if it is, then the player is in that enemy's field of vision.
----
so in playmaker terms, use the vector3 operator, set up two vector 3 variables and set it to Angle. Get the players vector3 and if it is in that range you use "You can Store Magnitude in Get Axis Vector and use Float Compare on that..."

and that is another way to do it!

---

I also found this vector3 compare that Julius created. http://hutonggames.com/playmakerforum/index.php?topic=3058.0

Thanks! How does this take into account obstacles blocking your view? With Raycasting the ray stops on the closest object.

The method described "just" checks if the target is in the cone of vision. If positive. Then you can perform a ray-casting -> fire one ray to your target to check if its blocked, If it hits the target then "tango is in sight".
This way you use only one ray per frame (or every 5 frames etc)

Title: Re: Best way to use raycasts for line-of-sight?
Post by: Adam Z on March 28, 2014, 12:40:23 PM
That makes sense. Let me see if I can get that to work. Thanks!
Title: Re: Best way to use raycasts for line-of-sight?
Post by: Adam Z on March 28, 2014, 01:11:33 PM
taken from the unity answers:

You want to calculate the direction between the enemy and the player, get the forward vector of the enemy, and then use Vector3.Angle to calculate the angle.

Then you can check if the angle is less than whatever angle you want to be the enemy's field of vision (eg: a 20 degree cone, for instance), and if it is, then the player is in that enemy's field of vision.
----
so in playmaker terms, use the vector3 operator, set up two vector 3 variables and set it to Angle. Get the players vector3 and if it is in that range you use "You can Store Magnitude in Get Axis Vector and use Float Compare on that..."

and that is another way to do it!

---

I also found this vector3 compare that Julius created. http://hutonggames.com/playmakerforum/index.php?topic=3058.0

Thanks! How does this take into account obstacles blocking your view? With Raycasting the ray stops on the closest object.

The method described "just" checks if the target is in the cone of vision. If positive. Then you can perform a ray-casting -> fire one ray to your target to check if its blocked, If it hits the target then "tango is in sight".
This way you use only one ray per frame (or every 5 frames etc)

I'm understanding this in theory, but I'm not sure how to set it up.  What Action can I use to get the Vector3 Angle?
Title: Re: Best way to use raycasts for line-of-sight?
Post by: sebaslive on March 28, 2014, 01:59:05 PM
vector 3 operator