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; }
protected virtual BehaviorReturnCode PickPointInFrontOfTargetExec() { GameObject targetGO = GetTargetFunc(); if (targetGO == null) { return(BehaviorReturnCode.Failure); } Vector2 charPos = charDriver.GetPosition(); Vector2 targetPos = targetGO.transform.position; // Add relative offset. Vector3 newDest = targetPos + (offset * ((charPos.x > targetPos.x)? 1 : -1)); SetDestnFunc(newDest); return(BehaviorReturnCode.Success); }
protected virtual BehaviorReturnCode SDSetFaceToTargetExec() { float originX = charDriver.GetPosition().x; float targetX = GetTargetFunc().x; // If target is to the right and we are not facing right. if ((((targetX >= originX) && !charDriver.IsFacingRight()) || // If target is to the left and we are facing right (targetX < originX && charDriver.IsFacingRight()))) { // If we entered in this block, the character isn't facing its target. So we need to check // if the reverse flag is set (which means that we don't need to face the target. if (!reverse) { charDriver.Flip(); } } return(BehaviorReturnCode.Success); }
bool IsArrivedAtDestinationTest() { return(IsArrivedAtDestination(GetDestnFunc(), charDriver.GetPosition(), offset, checkAxis)); }