A* Pathfinding Project  3.7.3
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
MineBotAI Class Reference

AI controller specifically made for the spider robot. More...

Detailed Description

AI controller specifically made for the spider robot.

The spider robot (or mine-bot) which is got from the Unity Example Project can have this script attached to be able to pathfind around with animations working properly.
This script should be attached to a parent GameObject however since the original bot has Z+ as up. This component requires Z+ to be forward and Y+ to be up.

It overrides the AIPath class, see that class's documentation for more information on most variables.
Animation is handled by this component. The Animation component refered to in anim should have animations named "awake" and "forward". The forward animation will have it's speed modified by the velocity and scaled by animationSpeed to adjust it to look good. The awake animation will only be sampled at the end frame and will not play.
When the end of path is reached, if the endOfPathEffect is not null, it will be instantiated at the current position. However a check will be done so that it won't spawn effects too close to the previous spawn-point.

Note
This script assumes Y is up and that character movement is mostly on the XZ plane.

Public Member Functions

override Vector3 GetFeetPosition ()
 
override void OnTargetReached ()
 Called when the end of path has been reached.
 
new void Start ()
 Starts searching for paths.
 
- Public Member Functions inherited from AIPath
void OnDisable ()
 
virtual void OnPathComplete (Path _p)
 Called when a requested path has finished calculation.
 
virtual void SearchPath ()
 Requests a path to the target.
 
float TrySearchPath ()
 Tries to search for a path.
 

Public Attributes

Animation anim
 Animation component.
 
float animationSpeed = 0.2F
 Speed relative to velocity with which to play animations.
 
GameObject endOfPathEffect
 Effect which will be instantiated when end of path is reached.
 
float sleepVelocity = 0.4F
 Minimum velocity for moving.
 
- Public Attributes inherited from AIPath
bool canMove = true
 Enables or disables movement.
 
bool canSearch = true
 Enables or disables searching for paths.
 
bool closestOnPathCheck = true
 Do a closest point on path check when receiving path callback.
 
float endReachedDistance = 0.2F
 Distance to the end point to consider the end of path to be reached.
 
float forwardLook = 1
 Target point is Interpolated on the current segment in the path so that it has a distance of forwardLook from the AI.
 
float pickNextWaypointDist = 2
 Determines within what range it will switch to target the next waypoint in the path.
 
float repathRate = 0.5F
 Determines how often it will search for new paths.
 
float slowdownDistance = 0.6F
 Distance from the target point where the AI will start to slow down.
 
float speed = 3
 Maximum velocity.
 
Transform target
 Target to move towards.
 
float turningSpeed = 5
 Rotation speed.
 

Protected Member Functions

new void Update ()
 
- Protected Member Functions inherited from AIPath
virtual void Awake ()
 Initializes reference variables.
 
Vector3 CalculateTargetPoint (Vector3 p, Vector3 a, Vector3 b)
 Calculates target point from the current line segment.
 
Vector3 CalculateVelocity (Vector3 currentPosition)
 Calculates desired velocity.
 
virtual void OnEnable ()
 Run at start and when reenabled.
 
IEnumerator RepeatTrySearchPath ()
 Tries to search for a path every repathRate seconds.
 
virtual void RotateTowards (Vector3 dir)
 Rotates in the specified direction.
 
float XZSqrMagnitude (Vector3 a, Vector3 b)
 

Protected Attributes

Vector3 lastTarget
 Point for the last spawn of endOfPathEffect.
 
- Protected Attributes inherited from AIPath
bool canSearchAgain = true
 Only when the previous path has been returned should be search for a new path.
 
CharacterController controller
 Cached CharacterController component.
 
int currentWaypointIndex = 0
 Current index in the path which is current target.
 
Vector3 lastFoundWaypointPosition
 
float lastFoundWaypointTime = -9999
 
float lastRepath = -9999
 Time when the last path request was sent.
 
float minMoveScale = 0.05F
 
NavmeshController navController
 Cached NavmeshController component.
 
Path path
 Current path which is followed.
 
Rigidbody rigid
 Cached Rigidbody component.
 
RVOController rvoController
 
Seeker seeker
 Cached Seeker component.
 
Vector3 targetDirection
 Relative direction to where the AI is heading.
 
Vector3 targetPoint
 Point to where the AI is heading.
 
bool targetReached = false
 Holds if the end-of-path is reached.
 
Transform tr
 Cached Transform component.
 

Additional Inherited Members

- Properties inherited from AIPath
bool TargetReached [get]
 Returns if the end-of-path has been reached.
 

Member Function Documentation

override Vector3 GetFeetPosition ( )
virtual

Reimplemented from AIPath.

override void OnTargetReached ( )
virtual

Called when the end of path has been reached.

An effect (endOfPathEffect) is spawned when this function is called However, since paths are recalculated quite often, we only spawn the effect when the current position is some distance away from the previous spawn-point

Reimplemented from AIPath.

new void Start ( )
virtual

Starts searching for paths.

If you override this function you should in most cases call base.Start () at the start of it.

See Also
OnEnable
RepeatTrySearchPath

Reimplemented from AIPath.

new void Update ( )
protectedvirtual

Reimplemented from AIPath.

Member Data Documentation

Animation anim

Animation component.

Should hold animations "awake" and "forward"

float animationSpeed = 0.2F

Speed relative to velocity with which to play animations.

GameObject endOfPathEffect

Effect which will be instantiated when end of path is reached.

See Also
OnTargetReached
Vector3 lastTarget
protected

Point for the last spawn of endOfPathEffect.

float sleepVelocity = 0.4F

Minimum velocity for moving.


The documentation for this class was generated from the following file: