public Vector2 TryToMove(Vector2 wantsToMoveAmount, Vector2 deltaPosition = default, MoveMode mode = MoveMode.HorizontalFirst) { Vector2 movedAmount = deltaPosition; foreach (MoveUnit moveUnit in mode.GetMoveUnits(wantsToMoveAmount)) { if (!RaycastHelpers.IsValidDistance(moveUnit.distance)) { continue; } movedAmount[moveUnit.axis] = moveUnit.dir * TryToMove(moveUnit.distance, moveUnit.dir, deltaPosition); } return(movedAmount - deltaPosition); }
private float GetAllowedMovementAt_Obsolete(float distance, Direction4 direction, Vector2 deltaPosition = default) { if (!RaycastHelpers.IsValidDistance(distance)) { return(0); } IEnumerable <CollisionMoveHit> raycasterHits = GetCollisionMoveHits(distance, direction, deltaPosition); float allowedDistance = distance; foreach (CollisionMoveHit raycasterHit in raycasterHits) { allowedDistance = collisionMoveController.GetAllowedMoveInto(raycasterHit, allowedDistance); } return(allowedDistance); }
private float GetAllowedMovementAt(float distance, Dir4 dir, Vector2 deltaPosition = default) { if (!RaycastHelpers.IsValidDistance(distance)) { return(0); } (RaycastHit2D[] raycastHits, int count) = raycaster.GetHits(distance, dir, deltaPosition); IEnumerable <RaycastHit2D> uniqueHits = collisionMoveHitsFactory.GetUnique(raycastHits, count); float allowedDistance = distance; foreach (RaycastHit2D hit in uniqueHits) { allowedDistance = collisionMoveController.GetAllowedMoveInto(hit, allowedDistance, dir); } return(allowedDistance); }
private (bool, float) GetJumpCornerCorrectionFor(float topMovementAmount, DirX rayDirX) { Dir4 rayDir = Dir4.FromXFloat(rayDirX); Bounds bounds = movement.boxCollider.bounds; float rayLength = jumpCornerCorrection; Vector2 upperCorner = BoundsHelpers.GetCorner(bounds, rayDirX, DirY.up); Vector2 rayDelta = new Vector2(-rayDirX * rayLength, topMovementAmount); Vector2 rayOrigin = upperCorner + rayDelta; RaycastHit2D cornerHit = RaycastHelpers.SingleHit(rayOrigin, rayLength, rayDir, movement.layerMask); if (CanBeCornerCorrected(rayLength, rayDir, cornerHit)) { float correctionValue = -rayDirX * (rayLength - cornerHit.distance); return(true, correctionValue); } return(false, 0); }
public float ForceMove(float distance, Direction4 direction) { if (!RaycastHelpers.IsValidDistance(distance)) { return(NoDistanceForceMove(direction)); } Vector2 origin = rigidbody.position; IEnumerable <CollisionMoveHit> raycasterHits = GetCollisionMoveHits(distance, direction); foreach (CollisionMoveHit raycasterHit in raycasterHits) { collisionMoveController.ForceMoveInto(raycasterHit, distance); } rigidbody.position = origin + direction.ToVector2(distance); return(distance); }
public (RaycastHit2D[], int) GetHits(Vector2 origin, float distance, Dir4 dir) { distance = RaycastHelpers.CeilDistance(distance); int rays = rayDeltas.Length; int edgeRayHitsCount = 0; for (int i = 0; i < rays; i++) { Vector2 rayOrigin = origin + rayDeltas[i]; (int singleRayHitsCount, RaycastHit2D[] singleRayHits) = RaycastHelpers.Raycast(rayOrigin, distance, dir, layerMask); if (edgeRayHitsCount + singleRayHitsCount > maxEdgeRayHitsCount) { return(ForceReturnOverHitsResults(edgeRayHitsCount, singleRayHitsCount, singleRayHits)); } Array.Copy(singleRayHits, 0, edgeRayHits, edgeRayHitsCount, singleRayHitsCount); edgeRayHitsCount += singleRayHitsCount; } return(edgeRayHits, edgeRayHitsCount); }
public float ForceMove(float distance, Dir4 dir) { if (!RaycastHelpers.IsValidDistance(distance)) { return(NoDistanceForceMove(dir)); } Vector2 origin = rigidbody.position; (RaycastHit2D[] raycastHits, int count) = raycaster.GetHits(distance, dir); IEnumerable <RaycastHit2D> uniqueHits = collisionMoveHitsFactory.GetUnique(raycastHits, count); foreach (RaycastHit2D hit in uniqueHits) { collisionMoveController.ForceMoveInto(hit, distance, dir); } Vector2 moveAmount = (Vector2)dir * distance; rigidbody.position = origin + moveAmount; return(distance); }