How to restrict movement to an area?
Hi!
I'm Currently working on a space strategy game where I'm able to select a unit and move it to where ever i click. However what i really want to do is, when i have selected a unit to then draw out a circle to indicate the max range that the unit can move to and restrict its movement to only be able to move to a location inside it. I'm fairly new to unity and i would like some help with how i would go about with accomplishing this.
Comment
Answer by _Fawn_ · Feb 02, 2017 at 01:59 PM
If anyone in the future find this, here is how i solved it and hopefully you may have some use for it too.
float distance = Mathf.Sqrt(Mathf.Pow((transform.position.x - targetPosition.x), 2) + Mathf.Pow((transform.position.z - targetPosition.z), 2));
if (distance <= maxDistanse)
{
MovePlayer ();
}