BehaviorReturnCode MoveToDestnExec() { // We may use X/8 of the offset distance to be considered close to a position. This way, we may ensure // the character will stop moving only if it's inside the destination area. // // I left this action binded to IsArrivedAtDestnConditional because they are often used together. float offset = IsArrivedAtDestnConditional.Offset / 8; Vector3 charPos = charDriver.GetPosition(); // Horizontal movement. float destnX = GetDestnFunc().x; float currPosX = charPos.x; if ((destnX - offset) > currPosX) { if (run) { charDriver.RunRight(); } else { charDriver.WalkRight(); } } else if ((destnX + offset) < currPosX){ if (run) { charDriver.RunLeft(); } else { charDriver.WalkLeft(); } } // Vertical movement. if (axisMvmt) { float destnY = GetDestnFunc().y; float currPosY = charPos.y; if ((destnY - offset) > currPosY) { if (run) { charDriver.RunUp(); } else { charDriver.WalkUp(); } } else if ((destnY + offset) < currPosY){ if (run) { charDriver.RunDown(); } else { charDriver.WalkDown(); } } } return BehaviorReturnCode.Success; }