Set up AI configuration||doc135565

September 20, 2022

Format

AIControl:setAiData(key, value)
  • The class to which the function belongs:AIControl

Description

Set the AI configuration information of the entity.


Parameters

The configuration used in the basic state, the editor will automatically set some fields when the entity AI is turned on, see the basic state of AI for details.

field Briefly type Defaults Description
idleProb Daze probability float 0.5 The probability of ai being in a daze when there is no target, the value is 0-1
idleTime Often in a daze int [10, 30] range random The duration of the daze (frame), array type, the two numbers are random
idleAction daze action string none The action to be played when ai enters a daze state
patrolDistance patrol range float none The switch of whether AI can walk randomly and the range of random walk, but the range that cannot walk will not exceed the territory
homeSize Territory float 10 ai can enter the state switch of going home, when ai leaves the territory, it will automatically return to the territory
isAIGoHomePos Back to the Dots of the Territory bool none If it is not configured, it will be within the territory, randomly select a coordinate (the random range of the target point is determined by patrolDistance), and return to the territory. If it is set to true, it will return to the original place, not random.
lossEnemyTime Attack memory time float 40 Prevent the enemy from attacking the AI and suddenly go to the place that the AI cannot see, the AI will not attack, this time (frame) ensures that the enemy disappears in the AI's field of vision, and can still attack the enemy within this time range
chaseDistance Chasing distance, sight distance float none 1. Whether there is a switch for chasing, in the process of chasing if the conditions for attack are found, it will give up chasing and enter the attack state 2. The visual distance, the coordinate of ai is the center of the circle, and this value is equivalent to the radius of the sector
chaseInterval duration of the chase state float 20 The duration (frame) of entering the chase state, after which the state will be re-switched or the possible target will be switched
chaseSkill Skills that can be unleashed while chasing table{"fullName":"myplugin/..skill name in editor","cdTime":"cooldowntimefloat"} none When entering a chase state, release a chase skill. See the AI skill configuration in detail
skillList List of skills that can be released by ai table{"attackDis":"attack distance float","fullName":"myplugin/..skill name in the editor","priority":"priority int"} none List of attack skills. See the AI skill configuration in detail
autoAttack Whether to attack automatically bool none When the ai doesn't hate the enemy, it will look for an attackable object from the field of vision
attackNpc Type of enemy attacked bool none When true, it will be able to attack any object, when false it can only attack the player
maxVisualAngle ai's field of view float 90 The field of view, the coordinates of ai are the center of the circle, and this value is equivalent to the angle of the sector
hatredTransfer Configure hate transfer bool none When a pet attacks ai, the aggro target of ai will go to find the owner of the pet (pets are equipped with this configuration)
minAttackHate Attack starts hatred float 0 Attack the target when the hatred value is reached
hateWay hatred decay float none When it is 1, no attenuation is used, otherwise it is the default attenuation formula: 10% attenuation per second. When the hatred value is less than 1, the target will be removed from the AI's hatred list.
avoidCliff Whether to enable to prevent falling off cliffs bool false Whether to enable cliff detection to prevent falling off cliffs
avoidCliffHight Definition of the height of a cliff float 6 When ai can step on the air to avoidCliffHight, it is judged as a cliff
meetCliffBackRun Whether you encounter a cliff and turn back bool none When you encounter a cliff, go back
meetCollisionBackRun Go back when you encounter an obstacle bool none When you encounter an obstacle, go back
meetCollisionEmptyRun Do not go when encountering obstacles bool none When encountering obstacles, do not go
chaseNearTarget chasing a chosen target bool false Choose the closest target while chasing
nextChaseInterval chase interval float 40 Reset the time interval for chasing the target
withoutYaw target-oriented bool false true to face the target point, false not to rotate
aiArrivedTransition Switch state after reaching the target point bool none Switch state after reaching the target point


Code Samples

on the entity object servermount script, set the entity's AI configuration field

When the entity AI is enabled, the editor will automatically set some fields, and the fields with the same name will be overwritten. For example: the battle status is checked in the AI configuration, and the chaseDistance field is set in the code. After calling startAI to open the entity AI, the editor will use AI The field of view distance in the configuration is used as a preset value to override the chaseDistance field

local control = this:getAIControl()
control:setAiData("danceAction", "happy_dance")