Forum rules - please read before posting.

detecting player by line of sight?

Is it possible and how? I can only see an action of NPC follows but that is only depending on a trigger or hotspot.

 In general how can I use the raycast features of Unity

Comments

  • edited June 2015
    You may want to add or child some collision circle to your Player with bigger radius to trigger whatever you need and experement with it.

    Your question is vague though. Do you mean an NPC detects your player/character as it moves nearby, like in a startegy game?
  • Yes to the latter
  • That is not a very easy question to answer. What you would do is have a script on every NPC that shoots rays directly at the player. The ray would shoot from the eyes of the NPC to a target on the player. For that you need to figure out the distance and angle from the startpoint of the ray to the endpoint. 

    The ray will return the first Collider object it hits. So you know that if that Collider belongs to the player, the NPC can see the player, and if its something else, then not. But you will probably want to limit casting rays in some way. It makes no sense shooting a ray directly from the eyes of the NPC through the back of its head, towards the player, for example. 

     You also might want to shoot multiple rays towards different targets attached to the player, otherwise when the player is 90% visible, but the ray is blocked for example by a plant that is blocking the last 10%, you get faulty results. 

    So yeah, its not a very easy thing to build 



  • Vector3 startpoint = [NPCs head/eyes]
    Vector3 direction = [the direction vector between your player and the NPC]
    RaycastHit hit;

    if (Physics.Raycast(startpoint , direction , out hit))
    {
    if(hit.transform.name == "NameOfYourPlayer")
    {
    //you hit your player
    }
    else
    {
    //you hit something else
    }
    }
  • Not good enough. I worked with PlayMaker before and now with AC just to avoid being involved with scripts.

    Playmaker has a Raycast Action From Game Object plus checking distance and whether it hit or not so at the end I had just 4 Actions to check whether the Player was within a distance and whether the raycast hit it which means it was seen.

    Now I could use this simple routine if I could trigger it from AC by sending an event ????

    would it be possible and can you give me a clue as to how to implement it?

  • AC can trigger PlayMaker Events through Actions - see section 12.1 in the manual.

    Essentially you want to write "PlayMakerIsPresent" in your game's scripting define symbols (in the Player Settings), to let AC know that it's safe to reference PlayMaker.  You can then use the Third-Party: PlayMaker Action to call a PlayMaker Event.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.