Summary
You’ve created one enemy John Lemon has to avoid, but that doesn’t seem like much of a challenge. It’s time to create another enemy that will increase the challenge for the player.
In this tutorial, you’ll:
- Create a dynamic Ghost enemy
- Write a custom script so Ghosts can patrol the haunted house
- Populate your game with enemies
- When you’ve finished the tutorial, your game will be full of enemies — and almost complete!
Objectives
- Implement a Moving Ghost Enemy: Introduce a dynamic ghost enemy into the game, capable of moving within the environment.
- Animate and Script the Ghost: Ensure the ghost has appropriate animations and scripts for dynamic interaction.
- Utilize Pathfinding: Set up pathfinding for the ghost using waypoints, allowing it to patrol and navigate the game environment.
- Test and Adjust Gameplay: Conduct gameplay testing to fine-tune the ghost’s movements and interactions for an optimal player experience.
Steps
Top of Form
- Create a New Scene: Save the current progress in a new scene for easy reference and further research.
- Setup Ghost Prefab: Locate and add the ghost model from the project assets to the hierarchy. Convert it into a prefab for editing.
- Animate the Ghost: Create a new animator controller named ‘Ghost’. Assign relevant animations, such as ‘Ghost Walk’, to this controller.
- Configure Animator Controller: Assign the newly created animator controller to the ghost in the inspector.
- Add Collider to Ghost: In prefab mode, attach a capsule collider to the ghost and adjust its properties like center, radius, and height.
- Implement Rigid Body: Add a rigid body component to the ghost and set it as kinematic for movement control.
- Setup Ghost as an Observer: Utilize the ‘Point of View’ prefab to make the ghost an observer, similar to the gargoyle setup in the previous tutorial.
- Configure Nav Mesh Agent: Add a Nav Mesh Agent component to the ghost for pathfinding capabilities.
- Create and Assign Waypoints: Develop waypoints to guide the ghost’s patrol route and assign them to the ghost’s pathfinding system.
- Organize Game Objects: Clean up the hierarchy by organizing ghosts, gargoyles, and waypoints under respective parent objects for clarity.
- Test the Scene: Run the game to observe the ghost’s dynamic behavior and interactions.
- Troubleshoot and Debug: Address any issues, such as the ghost not appearing or moving as expected, and make necessary adjustments.
- Save Progress: Regularly save the scene to preserve changes and facilitate further research and development.