- Home /
Question by
unity_gYh4tFwbdtYooA · Aug 14, 2018 at 10:49 PM ·
3dnavigationflyingy-axisfleeing
How to make NPCs flee from Player by flying and landing (3D),How to make bug fly away from Player (3D)
I want small bugs to fly away as soon as the Player triggers the sphere collider, then for the bugs to land on the ground again some distance away (3D). So far I can get the bugs to flee, but I haven't successfully lifted them off the ground. Any ideas?
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
for (int i = 0; i < bugs.Length; i++)
{
Animator anim = bugs[i].GetComponent<Animator>();
anim.SetBool("Fly", true);
Vector3 disToPlayer = (transform.position - Player.transform.position) * multiplier;
Vector3 newPos = transform.position + disToPlayer;
_agent.SetDestination(newPos);
}
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
for (int i = 0; i < bugs.Length; i++)
{
Animator anim = bugs[i].GetComponent<Animator>();
anim.SetBool("Fly", false);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How can I make 3d grid based movement for a strategy game on the y axis 0 Answers
Helocopter obstical avoidance (Navmesh agent) 3 Answers
Error in Code 1 Answer
Irregular Spherical Pathfinding 1 Answer
Navigate a still image 0 Answers