Skip to content

Instantly share code, notes, and snippets.

@ones0318
Last active October 23, 2018 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ones0318/699ec9696f2ba3174822eb0e22afc62c to your computer and use it in GitHub Desktop.
Save ones0318/699ec9696f2ba3174822eb0e22afc62c to your computer and use it in GitHub Desktop.
unity game script: follower
void Update()
{
if(stop) return;
float dist = (transform.position - Player.transform.position).sqrMagnitude;
if (dist > 20)
{
// get closer to player
Vector3 direction = transform.position - Player.transform.position;
Vector3 bodyOffset = new Vector3(Player.GetComponentInChildren<SkinnedMeshRenderer>().bounds.extents.x, 0, Player.GetComponentInChildren<SkinnedMeshRenderer>().bounds.extents.z);
Vector3 newPos = transform.position - (direction - bodyOffset);
mAgent.SetDestination(newPos);
}
mAnimator.SetBool("isWalking", IsNavMeshMoving);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment