By @chilly wind
Walk In Place Workaround: When your AI Boar just won't move and walk in place: I found a fix for that: You have to modify AIStateRoaming.cs and AIStateRoamingTemplate.cs as follows:
using UnityEngine;
using UnityEngine.Serialization;
namespace BLINK.RPGBuilder.AI
{
[Serializable, CreateAssetMenu(fileName = "New AI Roaming State Template", menuName = "BLINK/AI/Templates/Roaming Template")]
public class AIStateRoamingTemplate : AIStateIdleTemplate
{
public float MinDistanceToMove = 2f; //Snake
public float PauseDuration = 60;
public float RoamDistance = 15;
public float RoamPointThreshold;
public LayerMask roamGroundLayers;
public float roamTargetCheckInterval = 0.25f;
public bool roamAroundSpawner = true;
}
}```
First add the new variable as per above to AIStateRoamingTemplate.
Next, update AIStateRoaming.cs as follows:
**SEE ATTACHED MSG/TEXT FILE AT BOTTOM OF THIS POST, SCRIPT WAS TOO BIG TO FIT IN 1 MESSAGE**
Here is a summary:
Updated logic in the final versions of both AIStateRoaming and AIStateRoamingTemplate scripts:
AIStateRoamingTemplate: A new MinDistanceToMove property was added to the template to set a minimum distance threshold for the AI entity to start moving. This property helps to prevent the AI entity from walking in place when the roaming target is too close.
```public float MinDistanceToMove = 1f;```
AIStateRoaming: In the Execute method, the AI entity checks if it is not paused, and the distance to the roam target is greater than both the RoamPointThreshold and MinDistanceToMove. If these conditions are met, the AI entity moves towards the roaming point. Otherwise, the AI entity resets its movement.
csharp
Copy code
```if (!IsRoamingPaused && distanceToTarget > roamingTemplate.RoamPointThreshold && distanceToTarget > roamingTemplate.MinDistanceToMove)
{
ThisAIEntity.MoveAgent(RoamTargetPosition);
}
else
{
ThisAIEntity.ResetMovement();
}```
After calling ThisAIEntity.ResetMovement(), the AI entity checks if its movement has stopped by examining the magnitude of its agent's velocity. If the movement hasn't stopped, the AI entity generates a new roaming point by calling the GetNewRoamingPoint() method, which makes the AI entity attempt to move to the new point.
```if (ThisAIEntity.EntityAgent.velocity.magnitude > 0.1f)
{
GetNewRoamingPoint();
}```
The updated logic aims to prevent the AI entity from walking in place and ensures that the AI entity continues moving even if it initially fails to reset its movement.
Updated logic in the final versions of both AIStateRoaming and AIStateRoamingTemplate scripts:
AIStateRoamingTemplate: A new MinDistanceToMove property was added to the template to set a minimum distance threshold for the AI entity to start moving. This property helps to prevent the AI entity from walking in place when the roaming target is too close.
```public float MinDistanceToMove = 1f;```
AIStateRoaming: In the Execute method, the AI entity checks if it is not paused, and the distance to the roam target is greater than both the RoamPointThreshold and MinDistanceToMove. If these conditions are met, the AI entity moves towards the roaming point. Otherwise, the AI entity resets its movement.
csharp
Copy code
```if (!IsRoamingPaused && distanceToTarget > roamingTemplate.RoamPointThreshold && distanceToTarget > roamingTemplate.MinDistanceToMove)
{
ThisAIEntity.MoveAgent(RoamTargetPosition);
}
else
{
ThisAIEntity.ResetMovement();
}```
After calling ThisAIEntity.ResetMovement(), the AI entity checks if its movement has stopped by examining the magnitude of its agent's velocity. If the movement hasn't stopped, the AI entity generates a new roaming point by calling the GetNewRoamingPoint() method, which makes the AI entity attempt to move to the new point.
```if (ThisAIEntity.EntityAgent.velocity.magnitude > 0.1f)
{
GetNewRoamingPoint();
}```
