Search Unity

Navigating Avatar Around Game Map Issues: Avatar Hidden Inside Tiles & Click Animation

Discussion in 'Navigation' started by pinzhi, Oct 12, 2019.

  1. pinzhi

    pinzhi

    Joined:
    Oct 3, 2019
    Posts:
    2
    I am currently working on a tower defense game in Unity (2018.4). I am very new to this software and C#. Right now I have an avatar that moves around my game screen via a NavMesh plane.

    The orange box in my pic below shows where the transparent plane is sitting. My game map (brown and green) consists of textured tiles.

    upload_2019-10-12_15-46-34.png


    upload_2019-10-12_15-24-39.png

    My avatar is the gray thing you see on the screen. I use NavMeshAgent and a couple of scripts to move my avatar around based on where my mouse clicks on the game map.

    Below is a video of my avatar moving.

    ezgif.com-video-to-gif.gif

    I'm trying to get help for the following two issues.

    1) when I move my avatar to a more elevated place (i.e. higher stack of tiles) he disappears inside the tile (see gif). I want the avatar to either be standing on top of the tile or on a lower level next to it.

    2) when I click on a tile in the game map to direct my avatar to move there, I want some indication or animation of where I clicked. (i.e. an arrow or circle on the spot of my mouse click).

    Any help on this would be greatly appreciated.
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    You will have to put collission on the higher blocks so your character doesn't just walk through, and then rebake your NavMesh.
    In order to get your character then on these higher levels, you will have to manually set up OffMeshLinks at each elevation.

    For the animation, maybe just make a particle and spawn it on your click position.
    You can get the position to spawn the particle on with something like this (pseudocode).
    Code (CSharp):
    1. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    2. if(Raycast(ray, out RaycastHit hit)
    3. {
    4. GameObject.Instantiate(particle, hit.position);
    5. }