Hello there,
Currently, what my script does is move the Enemy do a specific distance away from the player. What I want the Enemy to do is go to the minDist to the player, which would mean the distance between the player and the Enemy is for example “3f” I have a variable called “minDist” for that… How would I go and implement that?
This is part of the script where the Movement happens:
else
{
timeBetweenMoveCounter -= Time.deltaTime;
myRigidBody.velocity = Vector2.zero;
if (timeBetweenMoveCounter < 0f)
{
moving = true;
if (Vector3.Distance(transform.position, thePlayer.transform.position) <= maxDist)
{
timeToMoveCounter = Random.Range(timeToMove * 0.75f, timeBetweenMove * 1.25f);
moveDirection = ((transform.position - thePlayer.transform.position).normalized) * (moveSpeed - 3);
}
}
}
All the Variables are floats in case that is important information.
Thanks for any help I can get!