NodeCanvas Forums › Support › Parallel node does not work correctly on first run › Reply To: Parallel node does not work correctly on first run
Hya Gavalakis, glad to see you’re alive 😉
Sure, here is the code for the custom tasks:
isTalking just checks the current value on another class, I know I can do this via the checkBoolean task but for now I prefer doing it like so:
1 2 3 4 5 6 7 8 9 10 |
public class IsTalking : ConditionTask { [GetFromAgent] protected MBActor actor; protected override bool OnCheck() { return actor.IsTalking; } } |
SetMoving is also very simple:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public class SetMoving : ActionTask { [GetFromAgent] private MBActorMovement actorMovement; public BBParameter<bool> value; protected override void OnExecute() { actorMovement.MovementEnabled = value.value; EndAction(); } } } |
FollowPath is a bit more complex and uses the A* package and generally it just sets the next point in a path for the npc to follow.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
public class FollowPath : ActionTask { [Location] public int LocationReference = -1; public Vector2[] Path; [GetFromAgent] private FollowerEntity followerEntity; private int currentIndex = 0; private Location location; protected override void OnUpdate() { if (followerEntity.reachedDestination) { currentIndex += 1; if (currentIndex >= Path.Length) { EndAction(); return; } followerEntity.destination = location.worldPosition + (Vector3)Path[currentIndex]; } } protected override void OnStop() { followerEntity.destination = followerEntity.transform.position; } protected override void OnExecute() { location = (Location)Vault.Get(LocationReference); followerEntity.updateRotation = false; followerEntity.destination = location.worldPosition + (Vector3)Path[0]; } } |
I am using the latest version (3.29), and it does look like this:
1 2 3 4 |
protected override void OnReset() { for ( var i = 0; i < finishedConnections.Length; i++ ) { finishedConnections<em class="d4pbbc-italic"></em> = false; } finishedConnectionsCount = 0; } |
I will try and replicate the issue again on a different tree.