How do i make an enemy that follows you and shoots at you?

Im making a deadpool shooter and I REALLY need that code. Any help is greatly appreciated.

1 Like

For the chase part,
qwer
for the shoot part, sorry but idk.
if you want better pathfinding for the enemies, idk again.

1 Like

Use the sprite data extension to throw projectiles.

1 Like

Thanks. i had the same problem.

1 Like

can you send the link to what game you’re making please and thank you

1 Like
2 Likes

A quick update: The enemies dont shoot but I have updated the game. There is a working katana and cutscenes. There’s a cutscene when you die and if you reach 55 score https://makecode.com/_i4VhjzfkxPVf

I havd the exact same problem here is my game if you want to see some code https://arcade.makecode.com/S71414-38650-97092-96697

over all i have a good solution for all of you
im makecode arcade there is a squareRoot() block
well in that block there is sin, cos and atan2
what we need to do is find the radians between two points using atan2 and make that into a velocity multiplier using cos and sin

how do we do that? well to find the radian between two points use somthing like this

dx = x2 - x1
dy = y2 - y1
radians = Math.atan2(dy, dx)

or


radians = Math.atan2(y2 - y1, x2 - x1)

then to set the speed of your projectile use sin and cos

mySprite.setVelocity(cos(radians) * speed, sin(radians) * speed)

it looks something like this
image

1 Like

sorry i forgot to put sin and cos
cos is for the vx and sin is for vy (sin/cos of the radians)
And in dy dont put (sprite).x - (value).x put (sprite).y - (value).y