Last active
October 23, 2018 15:54
-
-
Save ones0318/699ec9696f2ba3174822eb0e22afc62c to your computer and use it in GitHub Desktop.
unity game script: follower
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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