Crash 3D Enemies & AI

Share on Facebook0Email this to someoneShare on Google+0Share on LinkedIn0Tweet about this on Twitter0Share on TumblrShare on StumbleUpon0Pin on Pinterest0

Crash 3D will have enemies roaming the entire map. They will randomly decide which routes to chose so the enemy cars will go different directions every time the game is played. This removes the predictability factor in the game.

There will be a single spawn position on the map where enemies will be spawned.
When starting the game there will be only 1 enemy car spawned on the map along with you. After a fixed amount of time OR after a certain score has been reached, more enemies will spawn.
When you crash into the enemy head-on, the game will be over. If you can mange to ram into the enemy car from behind, you will be able to kill the enemy and earn extra score. The enemy will then re-spawn faster than before.
So on a technical side, what happens when the player has rammed into the enemy?
  1. A collision detection script checks to see if the game object collided with is actually the player.
  2. Stop all movement scripts
  3. The renderer on the enemy is turned off so the player cannot see it.
  4. The Collider of the enemy is turned off to avoid any collision issues
  5. Explosion sound is played
  6. Particle system is instantiated to simulate an explosion
  7. Wait for the sound and instantiation to complete
  8. Wait for the specified time before it can re-spawn
  9. Set the position and rotation of the enemy to be equal to the re-spawn position
  10. Increase the speed
  11. Turn on the renderer
  12. Turn on the collider
  13. Enable the movement script
AI Behind the Enemies
Enemies have a movement script controlled by a speed variable. The movement script moves the enemy forward at the speed specified by the speed variable. It also allows the enemy to swerve left and right randomly without hitting other game objects (buildings, walls, etc). To make this possible, the enemy spawns exactly in the middle of the road. After a random amount of time, the enemy decides to swerve left or right for a random amount of meters.
To check whether to stop swerving,  a Raycast is used on both sides of the enemy. If the Raycast hits anything that is closer than 2meters the enemy will stop swerving.
The enemy will also randomly decide to return to the middle of the road.
How does the enemy know when to turn?
A group of trigger boxes is placed everywhere the enemy can turn.  A trigger box is added just before the turn telling the enemy whether it can turn left,right or continue straight. Another trigger box in the centre of the turn is used to trigger the actual turn. So when the enemy hits the first box, it knows where it can go. When it hits the second box, it randomly decides between the possible turns and performs that turn.
See the screen shots for demonstration.

 

 

Enemy Trigger Box

Enemy Trigger Box

Enemy Trigger Box

Enemy Trigger Box

 

Share on Facebook0Email this to someoneShare on Google+0Share on LinkedIn0Tweet about this on Twitter0Share on TumblrShare on StumbleUpon0Pin on Pinterest0

2 thoughts on “Crash 3D Enemies & AI

  1. I simply want to tell you that I am just new to blogging and site-building and honestly enjoyed you’re blog site. Probably I’m planning to bookmark your site . You absolutely come with outstanding stories. Thank you for revealing your website.

  2. … [Trackback]

    […] Read More here: orbicgames.com/crash-3d-enemies-ai/ […]

Leave a Reply