0

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.

enter image description here

enter image description here

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 link to a video of my avatar moving.

https://forum.unity.com/threads/navigating-avatar-around-game-map-issues-avatar-hidden-inside-tiles-click-animation.759737/

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.

PineNuts0
  • 4,740
  • 21
  • 67
  • 112

1 Answers1

0

On #1:

Make sure your tile GameObjects have colliders. Set the layer of the avatar to "Ignore Raycast". Then call Physics.RayCast from a point at the same x and z coordinates as your avatar, but at a Y coordinate above the highest point a tile might reach. Set a mask on the call so that GameObjects on "Ignore Raycast" layer won't generate a hit. RayCast will return a coordinate from which you can retrieve a Y value and use it for your avatar's positioning about the tile. More info about calling Raycast can be found here - https://docs.unity3d.com/ScriptReference/Physics.Raycast.html .

On #2:

I don't think you shouldn't ask two questions, so I've intentionally not answered the second one. I recommend editing your question to remove question #2. And just ask a separate question on Stack Overflow. It's a better way to structure the information so that other people besides you can learn from answers given to your questions. I say this in a friendly way.

Erik Hermansen
  • 2,200
  • 3
  • 21
  • 41