protected virtual BehaviorReturnCode MoveForwardExec() { if (charDriver.IsFacingRight()) { if (run) { charDriver.RunRight(); } else { charDriver.WalkRight(); } } else { if (run) { charDriver.RunLeft(); } else { charDriver.WalkLeft(); } } return(BehaviorReturnCode.Success); }
bool IsTargetInRangeTest() { RaycastOrigins raycastOrigins = charDriver.GetRaycastOrigins(); bool isFacingRight = charDriver.IsFacingRight(); RaycastHit2D hit = CheckObjectInArea(raycastOrigins, isFacingRight, offset, targetLayer, range, radius); // May be necessary to check if the target is alive! return(hit.transform != null); }
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); }
public static void DisplayAttackAreaCircle(ICharacterDriver driver, float radius, Vector2 offset) { RaycastOrigins raycastOrigins = driver.GetRaycastOrigins(); bool isFacingRight = driver.IsFacingRight(); Vector2 center = ((isFacingRight) ? raycastOrigins.rightCenter : raycastOrigins.leftCenter); // Add offset. center.x += offset.x * ((isFacingRight) ? 1 : -1); center.y += offset.y; // Centralize. center.x += (radius / 2) * ((isFacingRight) ? 1 : -1); Gizmos.DrawWireSphere(center, radius); }
/// <summary> /// Display the attack area. /// </summary> /// <param name="driver">Character's driver.</param> /// <param name="range">Attack range.</param> public static void DisplayAttackArea(ICharacterDriver driver, Vector2 range, Vector2 offset) { RaycastOrigins raycastOrigins = driver.GetRaycastOrigins(); bool isFacingRight = driver.IsFacingRight(); Vector2 center = ((isFacingRight) ? raycastOrigins.rightCenter : raycastOrigins.leftCenter); // Add offset. center.x += offset.x * ((isFacingRight) ? 1 : -1); center.y += offset.y; // Centralize the central point. center.x += (range.x / 2) * ((isFacingRight) ? 1 : -1); Gizmos.DrawWireCube(center, new Vector3(range.x, range.y, 0)); }