seanrich92
New member
Hi,
I have been having problems with using BD for a simple pursue task. So the situation is that whenever an object with a behavior tree does pursue or even a simple version of it [1], the latest object that runs this code bugs out. It just runs the code once and would spam path completed on the console logs and would try to pursue randomly 10-20 seconds later. However, upon spawning the same object, the one that bugged out previously suddenly runs the code correctly and the latest one will bug out. This happens with any number of objects, it is always the latest one that bugs out while the others suddenly works as long as they're not the latest ones. Another thing that also works is that whenever I press my left mouse button, the bugged object suddenly does the pursue task then stop after completing the path while the others do it continuously.
I've also tested this outside BD, just running the same code in an monobehaviour update loop using SetDestination and it works flawlessly without the same problems with BD. I also use SetDestination on other movement tasks which works well like seek or some modified version of it. Any way to debug or figure out what's happening here?
Link to the video:
Pursue Example
I have been having problems with using BD for a simple pursue task. So the situation is that whenever an object with a behavior tree does pursue or even a simple version of it [1], the latest object that runs this code bugs out. It just runs the code once and would spam path completed on the console logs and would try to pursue randomly 10-20 seconds later. However, upon spawning the same object, the one that bugged out previously suddenly runs the code correctly and the latest one will bug out. This happens with any number of objects, it is always the latest one that bugs out while the others suddenly works as long as they're not the latest ones. Another thing that also works is that whenever I press my left mouse button, the bugged object suddenly does the pursue task then stop after completing the path while the others do it continuously.
I've also tested this outside BD, just running the same code in an monobehaviour update loop using SetDestination and it works flawlessly without the same problems with BD. I also use SetDestination on other movement tasks which works well like seek or some modified version of it. Any way to debug or figure out what's happening here?
C#:[1] Example code: using UnityEngine; namespace BehaviorDesigner.Runtime.Tasks.Movement.AstarPathfindingProject { public class SimplePursue : IAstarAIMovement { [Tooltip("How far to predict the distance ahead of the target. Lower values indicate less distance should be predicated")] public SharedFloat targetDistPrediction = 20; [Tooltip("Multiplier for predicting the look ahead distance")] public SharedFloat targetDistPredictionMult = 20; public GameObject target; public override void OnStart() { base.OnStart(); target = // gets the gameObject here targetPosition = target.transform.position; } // Pursue the destination. Return success once the agent has reached the destination. // Return running if the agent hasn't reached the destination yet public override TaskStatus OnUpdate() { SetDestination(Target()); return TaskStatus.Running; } private Vector2 Target() { // Calculate the current distance to the target and the current speed Vector2 targetVector = new Vector2(target.transform.position.x, target.transform.position.y); Vector2 transformVector = new Vector2(transform.position.x, transform.position.y); var distance = (targetVector - transformVector).magnitude; var speed = Velocity().magnitude; float futurePrediction = 0; // Set the future prediction to max prediction if the speed is too small to give an accurate prediction if (speed <= distance / targetDistPrediction.Value) { futurePrediction = targetDistPrediction.Value; } else { futurePrediction = (distance / speed) * targetDistPredictionMult.Value; } // Predict the future by taking the velocity of the target and multiply it by the future prediction var prevTargetPosition = new Vector2(target.transform.position.x, target.transform.position.y); // targetPosition = targetVector; Vector2 movement = targetVector + (targetVector - prevTargetPosition) * futurePrediction; return movement; } } }
Link to the video:
Pursue Example