Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to know if a part sees a certain object?

Asked by 6 years ago

Is there a specific way to do it instead of making a new part where, when it's touched some code will fire? I'm making it so that an NPC will react if the player is seen by it.

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

Yes, you should check out raycasting to do this:

http://wiki.roblox.com/index.php/Raycasting

http://wiki.roblox.com/index.php?title=API:Class/Workspace/FindPartOnRay

http://wiki.roblox.com/index.php?title=API:Class/Workspace/FindPartOnRayWithIgnoreList

This tutorial can also help you as an example:

http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun

Try casting a ray from the NPC to the player (as an optimization, consider only casting the ray if the players are not too far away to be seen in the first place).

Consider using the dot product to test if the player is behind the NPC, since unless they are aliens they probably can't see behind them: http://wiki.roblox.com/index.php?title=Dot_product

Ad

Answer this question