Patrol, alert, attack! Overview
- Look at the player.
- Shoot projectiles.
- Have a cone of vision.
- Chase the player.
- Attack using different patterns.
Nathan
Founder and teacher at GDQuest
The challenge of coding multiple mobs
- As you make mobs with increasingly complex behaviors, it can become challenging to coordinate many different functions that each have their own constraints. It's too easy to inadvertently tangle functions together.
- With only functions, you will always need a programmer to implement and modify every mob in the game. It's not very accessible to a designer teammate.
Finite State Machine
What you will learn
- Implement a simple finite state machine with a variable and an enum in a script.
- Implement a more complex state machine designed to scale and support games that take months to years of development.
- Code statesthat can be reused across different mobs, so you only have to code shared behaviors once.
State (Finite State Machine)
In state machines, a state is a specific behavior or set of behaviors that an entity can be in. For example, a mob can be in the "patrol" state, where it moves between waypoints, or in the "chase" state, where it runs towards the player. It's a bit different from when we talk about the state of a program, which is a snapshot of the current data the program put in the computer's memory at a given point in time. More on State (Finite State Machine) - Create a mob that turns to look at the player, pauses, and shoots a bullet at them.
- Create a mob that can charge at the player and sting them.
- Create a mob that walks towards the player, stomps the ground, and deals damage in an area around it.
- Implement mobs that take damage and die using hit and hurt boxes.
Nathan
Founder and teacher at GDQuest
More is less
Download the project files
Files not accessible
Looks like you don't own this course. Get it now.
Lesson Q&A
Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.