I'm trying to figure out how to return one result to the immediate parent, while returning a different one to the grandparent. The idea is: given a "turnToFaceTarget" tree, skip the rotation if already facing the right direction, and continue doing whatever's next. This means the condition node should return Failure to its parent (turnIfNeeded), but the parent should return Success to its parent (walkToPosition). How can we accomplish this?
I thought of using an invert
decorator, but I'm not sure how to implement it, since no nodes don't have a parent reference. I can think of ways to hack it, but... how is this "supposed" to be done?
walkToPosition:
sequence("walkToPosition") {
turnToFaceTarget // this should return Success when done turning
action("startWalking") {
}
}
// returns Success if/when facing the right way, and Running while it's turning
turnToFaceTarget:
selection("turnIfNeeded") {
condition("shouldTurn") {
// We want to optionally skip rotation (return Failure), but return an overall Success
return currentAngle == targetAngle ? Failure : Success
}
sequence("turn") {
action("setRotationVelocity") {
}
action("rotate") {
// apply rotation
return targetAngle == targetAngle ? Success : Running
}
}
}