public SuperspectiveRaycast GetRaycastHits() { Vector2 screenPos = PixelPositionOfReticle(); Ray ray = cam.ScreenPointToRay(screenPos); return(RaycastUtils.Raycast(ray.origin, ray.direction, interactionDistance, layerMask)); }
public SuperspectiveRaycast GetAnyDistanceRaycastHits() { Vector2 reticlePos = Reticle.instance.thisTransformPos; Vector2 screenPos = Vector2.Scale( reticlePos, new Vector2(SuperspectiveScreen.currentWidth, SuperspectiveScreen.currentHeight) ); Ray ray = cam.ScreenPointToRay(screenPos); return(RaycastUtils.Raycast(ray.origin, ray.direction, float.MaxValue, layerMask)); }
public void Update(Vector2 dimensions, Direction facingDir) { const float EPSILON = 0.1f; //the extra amount to cast -> higher values make snapping more noticeable but provide more reliability and better adhesion to moving platforms. var position = transform.position.ToV2(); float heightOffset = dimensions.y / 3; //gives our cast more room to detect the ground (guards cases where we overshoot cuz we are falling quickly) float castLength = dimensions.x * Mathf.Tan(MAX_SLOPE_RADIANS) + heightOffset + EPSILON; //detect slopes of up to the maxDetectionAngle var xOffset = dimensions.x / 2f; var centerPoint = position; var leftPoint = new Vector2(position.x - xOffset, position.y); var rightPoint = new Vector2(position.x + xOffset, position.y); var centerRay = new Ray2D(position + Vector2.up * heightOffset, Vector2.down); var leftRay = new Ray2D(leftPoint + Vector2.up * heightOffset, Vector2.down); var rightRay = new Ray2D(rightPoint + Vector2.up * heightOffset, Vector2.down); CastInfo centerCast = RaycastUtils.Raycast(centerRay, castLength, GameUtils.Layers.GroundMask); CastInfo leftCast = RaycastUtils.Raycast(leftRay, castLength, GameUtils.Layers.GroundMask); CastInfo rightCast = RaycastUtils.Raycast(rightRay, castLength, GameUtils.Layers.GroundMask); CastInfo castInfo = centerCast.didHit ? centerCast : (leftCast.didHit ? leftCast : rightCast); SetGroundedInfo(castInfo, heightOffset + EPSILON, facingDir); CheckForStateChange(); if (followMovingObjects) { ///Cover the case of moving platforms! if (IsGrounded && castInfo.didHit) { position.y = castInfo.hitInfo.point.y; transform.position = position.ToV3(); } ///TODO -> still need handling for horizontal movement of platforms; that is a bit more /// involved though so ill leave it for now until some level design decisions are sorted } #if DEBUG_MODE ///bottom positions on collider DebugUtils.DrawSquare(centerPoint, 0.035f, Color.yellow); DebugUtils.DrawSquare(leftPoint, 0.035f, Color.yellow); DebugUtils.DrawSquare(rightPoint, 0.035f, Color.yellow); if (centerCast.didHit) { DebugUtils.DrawSquare(centerCast.hitInfo.point, 0.05f, Color.blue); } if (leftCast.didHit && rightCast.didHit) { DebugUtils.DrawConnection(leftCast.hitInfo.point, rightCast.hitInfo.point, Color.blue, Color.blue, 0.05f); } else if (leftCast.didHit) { DebugUtils.DrawSquare(leftCast.hitInfo.point, 0.05f, Color.blue); } else if (rightCast.didHit) { DebugUtils.DrawSquare(rightCast.hitInfo.point, 0.05f, Color.blue); } DebugUtils.DrawArrow(centerRay.origin, centerRay.GetPoint(castLength), Color.red, 0.1f); DebugUtils.DrawArrow(leftRay.origin, leftRay.GetPoint(castLength), Color.red, 0.1f); DebugUtils.DrawArrow(rightRay.origin, rightRay.GetPoint(castLength), Color.red, 0.1f); DebugUtils.DrawArrow(position, position + GroundSlope * xOffset * 1.5f, Color.green, 0.1f); if (castInfo.didHit) { DebugUtils.DrawSquare(castInfo.hitInfo.point, 0.1f, Color.magenta); } #endif }