Basically I’ve made some butterflies for my game with an animator that makes them flutter around in the air and head towards the player, except instead of flying towards the player, they basically face-plant into the ground and hop over towards the player.
While this is hilarious, I just want to have it so the butterflies fly towards my player, here’s the script I’m using in case anyone knows how to modify it so they stay in the air:
// Use this for initialization
void Start () {
}
//The target player
public Transform Basehuman01b;
//At what distance will the enemy walk towards the player?
public float walkingDistance = 10.0f;
//In what time will the enemy complete the journey between its position and the players position
public float smoothTime = 10.0f;
//Vector3 used to store the velocity of the enemy
private Vector3 smoothVelocity = Vector3.zero;
//Call every frame
void Update()
{
//Look at the player
transform.LookAt(Basehuman01b);
//Calculate distance between player
float distance = Vector3.Distance(transform.position, Basehuman01b.position);
//If the distance is smaller than the walkingDistance
if(distance < walkingDistance)
{
//Move the enemy towards the player with smoothdamp
transform.position = Vector3.SmoothDamp(transform.position, Basehuman01b.position, ref smoothVelocity, smoothTime);
}
}
Again any advice is greatly appreciated