Jump to content

* * * * *
Contents


This tutorial covers setting up AI, pathfinding and events. We we learn how to use AI scripts and the navigation mesh generator to create an exiting FPS scene.

Attached Image: 1.PNG

Playing the Game

We start out with the FPS character controller. You will notice that this time we have a weapon loaded in front of us.

Attached Image: 2.PNG

Shoot the weapon by pressing the left mouse button. We can reload the weapon by pressing the 'R' key on your keyboard.

Attached Image: 3.PNG

The flashlight is attached to the player and can be toggled on and off with the 'F' key.

Attached Image: 4.PNG

Press E to interact with control panel which is located on the upper walkway in the wide hall.

Attached Image: 5.PNG

Music starts playing and soon enemies will appear. These enemies will attack you.  After killing the enemies, go down to the stairs and you will notice that the elevator has appeared. We can go on to this elevator, press the button on the control panel and use the elevator to continue the level.

Attached Image: 6.PNG

Flowgraph Editor

Open up the flowgraph editor. You can see that there are 3 control panels. If we select the control panel in the scene, it becomes highlighted in the flowgraph editor. The first control panel controls the elevator, sliding doors, activates music and the enemies.

Attached Image: 7.png

Select control panel if you haven't already done so. You can see that the ' PushButton' script is attached. Here we can specify which sond plays when the button is being used. We can also say whether it is enabled. If the enabled button is not enabled, interaction is not enabled.

Attached Image: 8.PNG

Once the control panel button is pressed in the scene, it calls the 'use' output. This calls the trigger Delay. This is a timer which counts down till it calls the output. That output on its term start playing music.

Pivots

Lets locate the music delay trigger in the scene. You will see a small icon in the scene. This represents a pivot. A pivot is a 3d point in your scene and nothing more. It doesn't render anything and it doesn't have physics. The pivot has the triggerDelay script attached. delay is set to 2.5 seconds. The second pivot has the noise.lua script attached. This is actual sound that plays.

Attached Image: 9.PNG

Doors

The 'Use output' also calls the Monsterdoor. It will open the door for us. The monster door is located halfway through the scene and prevents the player to see the monsters hiding behind it.

Attached Image: 10.PNG

Elevator

The elevator also uses the sliding door script. However, instead of going sideways it now goes up and down. The first control panel connects to the 'Open' input.

Attached Image: 12.PNG

Elevator Controls

The other 2 control panels also interact with the elevator. The control panel on the elevator itself (see image below) toggles the elevators state.

Attached Image: 13.PNG

The control panel at the bottom of the elevator shaft has a connection to the 'Close' input.

AI

Now lets have a look how the AI of the enemies has been set up. Select one of the monsters behind the locked door in your scene. You will the 'MonsterAI' script attached. when a monster is in range it will attack the player. Since it is not enabled it will not do anything.

Attached Image: 14.PNG

Let's go back to the flowgraph editor. We can see that when we press the button on the control panel it will activate the monster.

Once the monster has been activated it will move to the AI navpoint that we specified in the script. This navpoint is located at the bottom of the stairs in the wide hall. When the monster has reached the wide hall, it will spot the player and it will set its target to the player automatically.

Attached Image: 16.PNG

Weapons

How is the weapon set up? Locate in the scene tab. It has the FPS player script attached. We can say whether the flashlight works. We can attach a weapon prefab via the script so that the player starts the level with a weapon.

Attached Image: 20.png

We can also set the 'Team' of where our player belongs to. If we set it to 'Good' the enemy will not attack us. If we set it to 'Bad', the enemy will not attack us.

Attached Image: 19.png

Navmesh Generation

Leadwerks has the build in capacity to generate aq navigation mesh. In order to do so, go to Tools -> build Navmesh.

Attached Image: 22.png

A small menu appears with 2 options. The most important one is the 'Max edge length'. This determines how detailed your navmesh should be. The lower this number the longer it takes to generate.

Attached Image: 23.png

After you are done building the navmesh, it is automatically shown. The blue areas represent where NPC's can walk.

Attached Image: 17.PNG

You can toggle the view of the navmesh at any given time by going to View - Show navigation.

Attached Image: 24.png

Monster Door

Look at the door where the monsters hide behind. You can see that the navmesh goes through it. (as intended).

Attached Image: 21.PNG

If you don't want this to happen then go the physics tab of the selected object. Here you can see a checkbox that says 'Navmesh obstacle'. If we check it and rebuild the navmesh we see it does not generate a path through door.

Attached Image: 18.png


1 Comments

Correct this, please:

We we learn how to use AI scripts and the navigation mesh generator to create an exiting FPS scene.

You can see that the ' PushButton' script is attached. Here we can specify which sond plays when the button is being used.

You will [a word missing here] the 'MonsterAI' script attached. when a monster is in range it will attack the player.

We can also set the 'Team' of where our player belongs to. If we set it to 'Good' the enemy will not attack us. If we set it to 'Bad', the enemy will not attack us. [the red "not" is probably superfluous]