Why is the enemy freaking out when I move?

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 :thinking:
I’m not sure why that’s happening, but it more likely has to do with the enemy’s move code:

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)

:point_up: 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

thank you it works perfectly. top down enemies2-21-2023_10-01-47.wick

1 Like