private void MoveForwardUpdate() { float forwardTileSpeed = rotationFramesLeft == 0 ? moveTileSpeed : edgeMoveTileSpeed; Vector2 forwardDeltaMove = TileHelpers.TileToWorld(forwardTileSpeed) * rotation.GetFrontVector() * Time.deltaTime; Vector2 moveAmount = movement.TryToMove(forwardDeltaMove); if (raycaster.HasWallInFront()) { ReverseSnail(); } else if (raycaster.HasNoColliderBelow()) { if (goAround) { RotateSnail90(); } else { ReverseSnail(); } } }
internal bool HasWallInFront() { Vector2 extents = boxCollider.bounds.extents; Vector2 origin = boxCollider.bounds.center; Vector2 rayOrigin = origin; float skingWidth = Constants.SKIN_WIDTH; int axis = rotation.IsHorizontal() ? 0 : 1; float sign = transform.right[axis]; rayOrigin += Vector2Helpers.AxisVector(axis, sign * (extents[axis] - skingWidth)); Vector2 rayVector = rotation.GetFrontVector(); RaycastHit2D hit = CastRay(rayOrigin, rayVector, frontRayLength + skingWidth, frontRayLayerMask); return(hit == true); }