Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen an 'enemy' hits a waypoint, all the enemies go to the next waypoint in the queue... Why?
    primarykey
    data
    text
    <p>Here is the code I'm working on, I want all the enemies to go to each waypoint on their own accord; however, when one enemy hits the waypoint, all the enemies go to the next waypoint. How do I fix it?</p> <p>I am running this from main, I have an enemy class and I have passed the queue in as a parameter when my enemy gets created. The original queue is called 'wayQ', the copied one that my enemies use is called 'way'.</p> <p>Edit: Here is the enemy class. I modified the code to overide the main update method.</p> <pre><code>class Enemy : GameObject { public Texture2D texture; public float scale = 0.3f; public Queue&lt;Vector2&gt; way = new Queue&lt;Vector2&gt;(); private int atDestinationLimit = 1; public Enemy() { } public Enemy(ContentManager Content, int health, float speed, Vector2 vel, Vector2 pos, Queue&lt;Vector2&gt; wayQ) { this.Health = health; this.Speed = speed; this.velocity = vel; this.position = pos; this.IsAlive = true; this.texture = Content.Load &lt;Texture2D&gt;("SquareGuy"); this.center = new Vector2(((this.texture.Width * this.scale) / 2), ((this.texture.Height * this.scale) / 2)); this.centPos = this.position + this.center; this.way = wayQ; } public void Update(GameTime theGameTime) { if (way.Count &gt; 0) { if (Vector2.Distance(centPos, way.Peek()) &lt; atDestinationLimit) { float distanceX = MathHelper.Distance(centPos.X, way.Peek().X); float distanceY = MathHelper.Distance(centPos.Y, way.Peek().Y); centPos = Vector2.Add(centPos, new Vector2(distanceX, distanceY)); way.Dequeue(); } else { Vector2 direction = -(centPos - way.Peek()); direction.Normalize(); velocity = Vector2.Multiply(direction, Speed); centPos += velocity; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload