Trying to make and change states of AI
by Jack Harrison · in Torque 3D Beginner · 03/05/2013 (2:20 am) · 3 replies
I have some work to do for my university and I cannot find anywhere within my resources on how to create states and change them here is what I have been asked to do.
Add two new NPC properties called state and challengeRange. During the execution of the game the state property will have one of three values OBSERVE, GUARD, CHALLENGING. Initially its value will be GUARD however if a player enters the line of sight and is within sightRange but not challengeRange, state will be set to OBSERVE. If the player is within the line of sight and within challengeRange (which should be set to 30) then assign CHALLENGING to the state property. If in neither CHALLENGING or OBSERVE state the NPC should be in the GUARD state.Add the necessary logic to achieve this within the think method and test it by displaying the current state.
On top of this I have:
A non player character (NPC) is playing the role of a guard. It can be in one of five states PANIC, REGROUP, MONITOR, CHALLENGE and COMBAT. The guard has an arc of sight of 120 degrees and can see objects up to 80 game units away. He starts off with a moral level of 100 points but this is reduced by 2 points per second.
The rules for the state transitions are
The NPC starts off in a MONITOR state however if his moral falls below 30 points or a player moves into the arc of vision when its moral is less than 60 points, it moves into the PANIC state and retreats to the Waypoint named RetreatPoint. It waits there for 5 seconds before moving into the REGROUP state and returning to the original guard position (spawn point), where its moral is set back to 100 and its state changes back to MONITOR.
If a player moves into the NPC arc of vision while it is in the MONITOR state and the NPC’s moral is 60 or above, the NPC moves into the CHALLENGE state and moves to within 15 game units of the player’s position. Whilst in the CHALLENGE state its moral stops decrementing. After remaining stationary in the CHALLENGE state for three seconds it automatically moves into the COMBAT state and moves to within 5 game units of the player. A NPC can only remain in the COMBAT state whilst its moral is greater than 50, if it drops to 50 or less it must move into the PANIC state and withdrawal to the Retreat Point. Whilst in the COMBAT state his moral decrements by 5 points per second.
I am really struggling to figure out where even to start on all of this and it seems a bit over whelming, I have my ai.cs set up with line of sight and it can see my player character but I am so confused right now. Any help would be appreciated.
Add two new NPC properties called state and challengeRange. During the execution of the game the state property will have one of three values OBSERVE, GUARD, CHALLENGING. Initially its value will be GUARD however if a player enters the line of sight and is within sightRange but not challengeRange, state will be set to OBSERVE. If the player is within the line of sight and within challengeRange (which should be set to 30) then assign CHALLENGING to the state property. If in neither CHALLENGING or OBSERVE state the NPC should be in the GUARD state.Add the necessary logic to achieve this within the think method and test it by displaying the current state.
On top of this I have:
A non player character (NPC) is playing the role of a guard. It can be in one of five states PANIC, REGROUP, MONITOR, CHALLENGE and COMBAT. The guard has an arc of sight of 120 degrees and can see objects up to 80 game units away. He starts off with a moral level of 100 points but this is reduced by 2 points per second.
The rules for the state transitions are
The NPC starts off in a MONITOR state however if his moral falls below 30 points or a player moves into the arc of vision when its moral is less than 60 points, it moves into the PANIC state and retreats to the Waypoint named RetreatPoint. It waits there for 5 seconds before moving into the REGROUP state and returning to the original guard position (spawn point), where its moral is set back to 100 and its state changes back to MONITOR.
If a player moves into the NPC arc of vision while it is in the MONITOR state and the NPC’s moral is 60 or above, the NPC moves into the CHALLENGE state and moves to within 15 game units of the player’s position. Whilst in the CHALLENGE state its moral stops decrementing. After remaining stationary in the CHALLENGE state for three seconds it automatically moves into the COMBAT state and moves to within 5 game units of the player. A NPC can only remain in the COMBAT state whilst its moral is greater than 50, if it drops to 50 or less it must move into the PANIC state and withdrawal to the Retreat Point. Whilst in the COMBAT state his moral decrements by 5 points per second.
I am really struggling to figure out where even to start on all of this and it seems a bit over whelming, I have my ai.cs set up with line of sight and it can see my player character but I am so confused right now. Any help would be appreciated.
#2
03/05/2013 (5:35 am)
Thanks man, this seems great, this will really help a lot.
#3
03/05/2013 (8:31 am)
Mainly it points out one way to get the limited engine support for AI to function more intelligently. There are probably many good ways to do it - and there are a few great ways available on the store like the Tactical AI Kit and the Universal AI Starter Kit to name just two.
Torque Owner Richard Ranft
Roostertail Games
To use this, pull the repository down and then copy the scripts over top of a fresh project.