Once again, 7 hours of banging my head into the wall with solutions that barely work and make it look like there are 2 enemies has driven me back to the Unity Answers page. I’m getting more acquainted with this than I would like to admit…
Anyways, I am attempting to create an enemy that circles around the player, throwing individual knives and occasionally dashing in for a higher damage strike. The plan is that you can hit the enemy with melee attacks when it dashes in, and use currently unimplemented ranged weapons to hit it from afar. However, before I can even attempt to implement that, I am having difficulty making the enemy rotate. so far I have the script:
public float rotationSpeed;
public float rotationDistance;
public float dashSpeed;
public float dashTime;
public float speed;
public float attackDelay;
public float attack1Damage;
public float attack2Damage;
Vector3 axis = new Vector3(0f, 0f, 1f);
Transform player;
float lastAttackTime;
//bool isDashing = false;
void Start () {
player = GameObject.FindWithTag("Player").transform;
}
void Update () {
transform.RotateAround(player.position, axis, rotationSpeed * Time.deltaTime * 10f);
transform.rotation = Quaternion.identity;
}
Most of these values at the start aren’t used yet, but the important ones are rotationSpeed, rotationDistance, and speed. Those affect how the enemy rotates (How fast, how far away, and how fast to go back to the circle respectively), the rest are going to be used later. I used to have a few lines of code to move away from or towards the player depending on the Vector3.distance of the 2 objects, but that resulted in the enemy visibly wobbling between being too far away and too close, and in general was sub-optimal.
My question is, How can I use transform.RotateAround() while still maintaining a consistent distance? Thank you for any time you spent reading and (hopefully!) helping with this issue. Any advice with making the enemy’s brain work would also be greatly appreciated!