# How to make a chasing enemy?

I’m currently trying to figure out how to make a vampire walk toward the camera(player). The problem is that I don’t know how to make it constantly face in the direction of the player while moving foreward. I also am trying to make an item non-physical. Like a hologram. Also a detection zone that can start an event upon a player entering a certain area. Any way to do these things?

Here is how to make the character forever go to you (you can remix it)

(it’s in the gallery)

2 Likes

Make the object face you and go forward and repeat.

Hello i am wondering how to make an enemy chase the player through a house with walls. whenever i try the monster goes through walls. when i turn physics on it just stands there walking into the wall. It would be really cool if i could make the monster pathfind. thankyou

Ask @techleapnz or @EdTechnocation these Guru’s have always a bound of solutions.

A path/line is made up of lots of points, so to make a path from the camera’s position/movement we must collect and store those points in a list, so that we can tell a following character to move from point to point.

We would only want the character to follow the path if it can’t see the camera directly (search this forum for “RayCast”). This means it would have to move to the nearest point on the path, so we have to calculate this by looping through the list and finding the smallest distance between the character and each point.

This is the basic idea; there are more complications which you’ll encounter, but it gives you a starting point.

Hope that helps! Let me know if you have any further questions.

Geoff@TechLeap

Thank you for responding! I have 2 questions: does this all have to be done in the java script,or can i use the coblocks coding thing because i have never done scripting before. and can you please show me an example of this were the character/object is following the camera? Thank you so much

Only RayCasting requires JavaScript - the rest can be done in CoBlocks.

I don’t have an example, but I have outlined the coding needed to create this functionality in my post above.

If it’s not clear for you, or if you are unsure how to code certain parts, let me know.

Karawhiua! Go for it!

Geoff@TechLeap

1 Like

thanks it really useful for me

Hi - I was trying to access this space and make a similar code but the link does not work. Can I find this or something similar somewhere? My students are trying to get a dinosaur to chase an object attached to the camera.

Hi @Kasey_Smith,

The following remixable CoSpace gives basics code and physics setup for following an object:

Hope that helps!

Geoff @ TechLeap

Thanks for sharing, Geoff. For whatever reason, when I click on it the “Access Denied” screen pops up. I am logged in with my CoSpaces account and profile and am a Pro user. Is there something else I am missing to make this visible to me?

That’s weird - try searching the Gallery (using the Search bar at the top) for “zombie” to find it.

Geoff

Thanks, Geoff. I also cannot find this by searching “Zombie” in the Gallery. My gallery just spins until it stops working. I am unsure what the issue is. Is there a YouTube video about creating this effect that I could be directed to (I tried searching on YouTube as well but came up empty). Thanks!

Try again - the servers were down yesterday.

hello its been a while but i got back into coding and i was gonna give ray casting another shot but i dont know where to start like im not trying to make a shadow i just want to make an enemy or whatever chase the player around a house or whatever without going throgh walls and stuff sorry if i seem demanding i just really want to do that ill show an example

@techleapnz itd be nice if you would possibly add the raycasting part or modify it so i could try to replicate it thanks

A good place to start is to search this forum for “raycasting”, remix some of the projects, and see if you can figure out how it works.