Well, they say pictures are worth a thousand words, but I’ll try to summarize what I’m trying to do if the picture attached is confusing.
Basically, I’m trying to get a foe, for example, to move towards it’s target, but once it gets a certain (x) distance away, I want to modify it’s directional vector to where it will allow the foe to circle around it’s target.
I also intend to give the foe a dodging/evasion like behavior that will allow the enemy to jump to the side in a quarter-circling fashion.
I started off (thanks Google) with making a ring/circle of gameobjects (not sure if this is efficent in the long run), and I’m thinking about sorting them in a list, and possibly having the foe moving in between each point over time.
/// <summary>
/// Create a circle ring with gameObjects
/// </summary>
void DrawCircle()
{
float x, y;
float length = 5;
float angle = 0.0f;
float angleStepSize = 0.3f;
// go through all angles from 0 to 2 * PI radians
while (angle < 2 * Mathf.PI)
{
// calculate x, y from a vector with known length and angle
x = length * Mathf.Cos(angle);
y = length * Mathf.Sin(angle);
Vector3 loc = new Vector3(x, 0, y);
GameObject p = (GameObject)GameObject.Instantiate(point,loc,Quaternion.identity);
p.transform.parent = this.transform;
angle += angleStepSize;
}
}
Thanks in advance!
Loius
2
What I sorta did for a similar thing (bullet hell game basically):
/* enemy and player are Transforms */
Vector3 direction = player.position - enemy.position;
enemy.forward = direction;
if ( direction.magnitude < distance ) { enemy.position += enemy.right * speed; }
else { enemy.position += enemy.forward * speed; }