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.

2 Likes

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
4 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

omg, your game is so fun! I loved it!!!

Welcome to the code-munity spongeDryer!

1 Like

heh, why thank you !! i love your pfp, its so cute!!! is it your cat or just from the web??

The web. My cats are cuter hehehehehheh

use the thingy from the sprite utils extension. idk how to explain it but I’m sure @WoofWoof can

1 Like

Lowkey there is an easier way to do it without trig.

Dx and dy is as set

Set distance to sqrt (dx^2+dy^2)

Vx = dx/distance

vy = dy/distance