ScratchData LogoScratchData
Back to kriblo_test's profile

Example: Simple Line-of-sight enemy movement

KRkriblo_test•Created September 13, 2021
Example: Simple Line-of-sight enemy movement
6
3
121 views
View on Scratch

Instructions

This is a very simple example of how you can get enemies (in a game) to move towards the player, if there is a clear line of sight. Look at the code in the Enemy sprite, especially the "Tick" and "line-of-sight = Test" custom blocks. In this example, enemies also have a maximum radius of sight (how far they can see), so you have to get close enough for them to follow the Player. Use the arrow keys to control the Player (green) in this example. Click the green flag to re-randomize enemies. This example was in response to a question here: https://scratch.mit.edu/studios/25643089/comments/#comments-160845635 All code by me (@kriblo). Do you need / want enemies who can go around corners to find your Player? You might use some sort of pathfinding algorithm. Google it, or start by checking out my project "Example: Level Heat Map": https://scratch.mit.edu/projects/523619426/ https://scratch.mit.edu/projects/523619426/

Project Details

Project ID569596529
CreatedSeptember 13, 2021
Last ModifiedSeptember 14, 2021
SharedSeptember 13, 2021
Visibilityvisible
CommentsAllowed