-
Search Results
-
I have a very basic AI test project. In this project, I have a Target and an Enemy. In the BT, I meant to use a PARALLEL for the header, but accidentally changed it using ‘switch to’ to a SEQ while playing around (its a bit of a gotchya that it doesn’t change the name of the node when you do this switch, although I can see why it has this behaviour. Perhaps if the node has the default name though, it should be switched to the correct name of the node on using ‘Switch To’, to avoid confusion).
Anyway, using the SEQ, I noticed a strange behaviour. Specifically, I have this setup:
SEQ (repeat forever)
- DETECT (until success) - this sets a form variable DetectTargetPos
- MOVE (forever)I would have expected the detect to null the DetectTargetPos once the target was out of detection range. However, this doesnt happen - if I move the target out of range of the Enemy, it still moves to the target. HOWEVER, if I click ‘Debug Break’ on any of these nodes, then the DetectTargetPos variable IS nulled (and so the enemy stops chasing). This happens even if I double click the Debug Break quickly enough that it doesn’t actually get hit, so doesn’t pause the game. So, behaviour when I double click ‘Debug Break’ is different to when I dont.
I’ve moved my header node back to a PARALLEL which works fine for me, but would like to know exactly why using the Debug Break option is giving different behaviour when I use it to when I dont? I thought Debug Break was simply setting a breakpoint, but it seems to be forcing some sort of refresh?
If necessary, I can upload my sample project, but it should be simple to replicate. I’m running RAIN 2.1.6.1 which I believe is the latest.
Hello all,
I’ve been following along @CodersExpo ‘s tutorials and had no issues until the last and final tutorial.
I seem to be having issues with the custom action and the wander.
Basically, I am able to get the character to run at the hero, wave (instead of punch) when within the “near” detector range, and whilst within his normal patrol route, idle randomly within the timer intervals set in BT.
Afterwards, we had been advised to get the custom action created to allow the character to wander after the Hero takes cover and removes himself from line of sight. At that point, I have the parallel node showing a failure and the waypoint path node showing a failure as well. It seems odd because it states that the execution of the previous “WanderLocation” custom action is succeeding as needed.
For reference,
BT:
->PAR-RPT:Never, Fail:Any, Succeed:Any, TieBreaker:Fail ->->Detect-Sensor:"eyes", Aspect:"aHero", FormVariable:varHero ->->Detect-Sensor:"close", Aspect:"aHero", FormVariable:varNear ->->Selector ->->->Constraint(TreeHereWorksPerfectly) ->->->Constraint(TreeHereWorksPerfectly) ->->->Constraint-Constraint:varHero == null && isSearching (shows fail) ->->->->Custom Action - Name:WanderLocation, Assembly:(global), Class:WanderLocation (Succeeds) ->->->->PAR - RPT:Never, Fail:Any, Succeed:Any, TieBreaker:Succeed (Fails) ->->->->->WaypointPath - WaypointNetwork:"Wander", PathTarget:varNext, MoveTargetVariable:varMoveTo (Fails) ->->->->->->Move-MoveTarget:varMoveTo, MoveSpeed:3 (NeverCalled) ->->->->->Animate - AnimationState:Walk (fails)
Custom Action Script “WanderLocation”:
using UnityEngine; using System.Collections; using System.Collections.Generic; using RAIN.Action; using RAIN.Core; using RAIN.Navigation; using RAIN.Navigation.Graph; [RAINAction] public class WanderLocation : RAINAction { private static float _time = 0f; public override void Start (RAIN.Core.AI ai) { base.Start (ai); _time += Time.time; } public WanderLocation () { actionName = "WanderLocation"; } public override ActionResult Execute (RAIN.Core.AI ai) { Vector3 loc = Vector3.zero; List<RAINNavigationGraph> found = new List<RAINNavigationGraph> (); do { loc = new Vector3 (ai.Kinematic.Position.x + Random.Range (-8f, 8f), ai.Kinematic.Position.y, ai.Kinematic.Position.z + Random.Range (-8f, 8f)); found = NavigationManager.Instance.GraphsForPoints (ai.Kinematic.Position, loc, ai.Motor.StepUpHeight, NavigationManager.GraphType.Navmesh, ((BasicNavigator)ai.Navigator).GraphTags); } while((Vector3.Distance(ai.Kinematic.Position, loc)<2f)||(found.Count == 0)); ai.WorkingMemory.SetItem<Vector3> ("varMoveTo", loc); if (_time > 5000f) { ai.WorkingMemory.SetItem ("isSearching", false); } return ActionResult.SUCCESS; } public override void Stop (RAIN.Core.AI ai) { base.Stop (ai); } }
So essentially, the character will run on the spot after losing detection and is set to “isSearching”, and after 5 seconds or so, he will then return to the normal patrol route. This is unexpected behaviour, simply because he should instead be wandering around searching on the waypoint network for signs of the hero.
Would really appreciate the assistance to wrap my head around RAIN AI.
Cheers.