make agent walk if he can see the target point
i want to make a top down maze like game with the user having to click to make the navmesh agent move, but if you click somewhere on the other side of a wall the navmesh generates the entire path. i only want the character to move to the point if it can see it directly or walk into the direction of the click (until he hits a wall) my current code is using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class navigation : MonoBehaviour { public Camera Cam; public NavMeshAgent agent; void Start () { } void Update () { if(Input.GetMouseButtonDown(0)) { Ray ray = Cam.ScreenPointToRay (Input.mousePosition); RaycastHit hit; if (Physics.Raycast (ray, out hit)){ agent.SetDestination (hit.point); } } } }
how would i go about this?
Your answer
Follow this Question
Related Questions
Any good procedural generated maze for 2d out there? 0 Answers
How to get a list of the closest distance targets with NavMesh. 0 Answers
How to create car ai that moves around searching for player 0 Answers
Click to Move Game tutorial - walking animation issue 0 Answers
How do I calculate a Vector3 from the transform of a GameObject? 0 Answers