Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Need help with the demo

Discussion in 'Getting Started' started by Oleg_Temple, Nov 25, 2019.

  1. Oleg_Temple

    Oleg_Temple

    Joined:
    Nov 25, 2019
    Posts:
    1
    Hi, I am working on a demo program and got stuck. Imagine the situation, when you have 2 entities going
    perpendicularly to each other. Is there a way to make entity 1 "reserve" the section, so the entity 2 won`t collide with him and the entity 1 will pass safely? As a base, I want to take this rts kind controls

    public class PlayerControls : MonoBehaviour
    {
    private Camera mainCamera;
    private UnityEngine.AI.NavMeshAgent agent;

    void Start()
    {
    mainCamera = Camera.main;
    agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
    }

    // Update is called once per frame
    void Update()
    {
    if(Input.GetMouseButtonDown(0))
    {
    RaycastHit hit;
    if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit))
    {
    agent.SetDestination(hit.point);
    }
    }
    }
    }