im making a few enemies and I need to figure out why the circle enemy is freaking out when you move while its chasing so I can fix it and make the other enemies. here is the file top down enemies.wick.
It seems like the enemy is freaking out whenever the player is moving and en.ischase is true
I’m not sure why that’s happening, but it more likely has to do with the enemy’s move code:
speedFactor=3;
this.x += Math.cos(this.rotation)*speedFactor;
this.y += Math.sin(this.rotation)*speedFactor;
You can change this with another following code if you’d like:
// Difference in X & Y positions
var diff={
x: p.x-this.x,
y: p.y-this.y
}
var maxSpeed=4; // maximum speed (limit)
this.x+=Math.min(Math.max(-maxSpeed,diff.x),maxSpeed);
this.y+=Math.min(Math.max(-maxSpeed,diff.y),maxSpeed);
This follow code works by getting the difference in X and Y, and adding that to the XY position of the enemy, while staying under a speed limit (which is the “maxSpeed” variable).
I hope it works the way you need it to