Exemple #1
0
 public override void Update(float deltaTime)
 {
     miniDashTimer = Mathf.Approach(miniDashTimer, 0, deltaTime);
 }
Exemple #2
0
		/// <summary>
		/// casts a line through the spatial hash and fills the hits array up with any colliders that the line hits.
		/// https://github.com/francisengelmann/fast_voxel_traversal/blob/master/main.cpp
		/// http://www.cse.yorku.ca/~amana/research/grid.pdf
		/// </summary>
		/// <returns>the number of Colliders returned</returns>
		/// <param name="start">Start.</param>
		/// <param name="end">End.</param>
		/// <param name="hits">Hits.</param>
		/// <param name="layerMask">Layer mask.</param>
		public int Linecast(System.Numerics.Vector2 start, System.Numerics.Vector2 end, RaycastHit[] hits, int layerMask)
		{
			var ray = new Ray2D(start, end);
			_raycastParser.Start(ref ray, hits, layerMask);

			// get our start/end position in the same space as our grid
			var currentCell = CellCoords(start.X, start.Y);
			var lastCell = CellCoords(end.X, end.Y);

			// what direction are we incrementing the cell checks?
			var stepX = Math.Sign(ray.Direction.X);
			var stepY = Math.Sign(ray.Direction.Y);

			// we make sure that if we're on the same line or row we don't step in the unneeded direction
			if (currentCell.X == lastCell.X) stepX = 0;
			if (currentCell.Y == lastCell.Y) stepY = 0;

			// Calculate cell boundaries. when the step is positive, the next cell is after this one meaning we add 1.
			// If negative, cell is before this one in which case dont add to boundary
			var xStep = stepX < 0 ? 0f : (float) stepX;
			var yStep = stepY < 0 ? 0f : (float) stepY;
			var nextBoundaryX = ((float) currentCell.X + xStep) * _cellSize;
			var nextBoundaryY = ((float) currentCell.Y + yStep) * _cellSize;

			// determine the value of t at which the ray crosses the first vertical voxel boundary. same for y/horizontal.
			// The minimum of these two values will indicate how much we can travel along the ray and still remain in the current voxel
			// may be infinite for near vertical/horizontal rays
			var tMaxX = ray.Direction.X != 0 ? (nextBoundaryX - ray.Start.X) / ray.Direction.X : float.MaxValue;
			var tMaxY = ray.Direction.Y != 0 ? (nextBoundaryY - ray.Start.Y) / ray.Direction.Y : float.MaxValue;

			// how far do we have to walk before crossing a cell from a cell boundary. may be infinite for near vertical/horizontal rays
			var tDeltaX = ray.Direction.X != 0 ? _cellSize / (ray.Direction.X * stepX) : float.MaxValue;
			var tDeltaY = ray.Direction.Y != 0 ? _cellSize / (ray.Direction.Y * stepY) : float.MaxValue;

			// start walking and returning the intersecting cells.
			var cell = CellAtPosition(currentCell.X, currentCell.Y);

			// Debug.log( $"cell: {currentCell.X}, {currentCell.Y}" );
			// debugDrawCellDetails( intX, intY, cell != null ? cell.Count : 10 );
			if (cell != null && _raycastParser.CheckRayIntersection(currentCell.X, currentCell.Y, cell))
			{
				_raycastParser.Reset();
				return _raycastParser.HitCounter;
			}

			while (currentCell.X != lastCell.X || currentCell.Y != lastCell.Y)
			{
				if (tMaxX < tMaxY)
				{
					// HACK: ensures we never overshoot our values
					currentCell.X = (int) Mathf.Approach(currentCell.X, lastCell.X, Math.Abs(stepX));

					// currentCell.X += stepX;
					tMaxX += tDeltaX;
				}
				else
				{
					currentCell.Y = (int) Mathf.Approach(currentCell.Y, lastCell.Y, Math.Abs(stepY));

					// currentCell.Y += stepY;
					tMaxY += tDeltaY;
				}

				// Debug.log( $"cell: {currentCell.X}, {currentCell.Y}" );
				cell = CellAtPosition(currentCell.X, currentCell.Y);
				if (cell != null && _raycastParser.CheckRayIntersection(currentCell.X, currentCell.Y, cell))
				{
					_raycastParser.Reset();
					return _raycastParser.HitCounter;
				}
			}

			// make sure we are reset
			_raycastParser.Reset();
			return _raycastParser.HitCounter;
		}
Exemple #3
0
 public override void Update(float deltaTime)
 {
     playerStateMachine.fullDashCooldownTimer = Mathf.Approach(playerStateMachine.fullDashCooldownTimer, 0, deltaTime);
 }