This is an overview of the Speeddrake_AI Script.
The string "personality" greatly controls the velocidrake's actions, colored orange.
Coward: Will run away when the player is standing too close.
Savage: Will attack the player from any distance.
Guard: Will not leave past a specific zone.
Persist: Will follow the player relentlessly.
Agile: Will jump over and avoid projectiles.
VOID Start() Reads and stores component variables.
VOID OnEnable() Resets AI states
VOID Update() Controls the meat of the AI.
- Sets basic variables
- Checks distance from player.
- Most vDrakes become inactive if too far away.
- Persist vDrakes will instead chase after the player.
- Guard vDrakes will check the distance from the guardzone instead of itself.
- Agile vDrakes check around themselves for incoming projectiles, and will jump into the air if there are any incoming threats. If the threat is too high, they will instead attempt to drop lower to the ground.
- Basic functions are then called. There are 4 wall checking variables, to test whether or not the vDrake is on a wall.
- The wallhitx variables check for standing on walls.
- The wallcheckx variables check the distance to the hit wall, and positions the vDrake appropriately.
- The floor underneath the vDrake is then checked. If in the air, and not on a wall, the vDrake will be affected by gravity.
- Now the script checks to ensure the player is within the vDrake's attack field, and their position.
- Guard vDrakes at this point check their distance to their guard point, and Retreat if too far away.
- The following action is randomized by a variable between 0 and 5.
- Climb will jump backwards to go up a wall.
- Fall will jump down from the wall, or move closer to the player.
- Attack will tackle the player, landing on the other side.
- Debugging variables are checked last.
VOID wallChecknFace() Checks for walls, and quickly sets the vDrake's position and facing direction based on the results.
VOID circleCheck(LayerMask layerFloor, Vector2 chaseSpotT, LayerMask layerWall, Vector2 chaseMove) Creates a circle that moves and grows.
VOID jumpToPoint(Vector2 jumpPoint, int jumpspd, float xspd, bool attackDash) rapidly moves the vDrake towards the desired point, found by circleCheck().
VOID projectCheck() If the vDrake is agile, constantly checks for nearby projectiles through a circlecast.
VOID actionMove (string currAct) Performs the desired action.
The string "currAct" controls the vDrake's action, colored red.
- Attack: Will find a location behind the player, and tackle towards that spot.
- If Savage the distance to be checked increases.
- If Safe and Guard the vDrake instead retreats.
- If Safe and isn't guard the vDrake instead attempt to Attack Safe.
- Attack Safe: Will find a location between the vDrake and player, just to get closer.
- Climb: Looks behind itself to find a wall that can be jumped on. This action happens quickly, and there is no prepping animation.
- Fall: Similar to Climb, but looks instead to the front for a floor to land on.
- RunAway: Finds any location behind the vDrake, and falls back.
- If running away Fast, will increase the bubble's speed and decrease the prep time.
- Retreat: Will jump back towards their guard location, used by Guarders.
- After everything is checked, the variable curruentAction is reset to be blank.
VOID OnTriggerStay2D(Collider2D other) Checks if colliding with the player.If colliding with the player and tackling, the player will be damaged.
No comments:
Post a Comment