Exemple #1
0
		internal void setValues( Collider collider, float fraction, float distance, Vector2 point )
		{
			this.collider = collider;
			this.fraction = fraction;
			this.distance = distance;
			this.point = point;
		}
Exemple #2
0
		public RaycastHit( Collider collider, float fraction, float distance, Vector2 point, Vector2 normal )
		{
			this.collider = collider;
			this.fraction = fraction;
			this.distance = distance;
			this.point = point;
			this.normal = normal;
			this.centroid = Vector2.Zero;
		}
Exemple #3
0
		void notifyTriggerListeners( Collider self, Collider other )
		{
			// notify any listeners on the Entity of the Collider that we overlapped
			other.entity.getComponents( _tempTriggerList );
			for( var i = 0; i < _tempTriggerList.Count; i++ )
				_tempTriggerList[i].onTriggerEnter( self, other );

			_tempTriggerList.Clear();

			// notify any listeners on this Entity
			entity.getComponents( _tempTriggerList );
			for( var i = 0; i < _tempTriggerList.Count; i++ )
				_tempTriggerList[i].onTriggerEnter( other, self );

			_tempTriggerList.Clear();
		}
Exemple #4
0
		public override void onAddedToEntity()
		{
			_collider = entity.getComponent<Collider>();
			Assert.isNotNull( _collider, "null Collider. ProjectilMover requires a Collider!" );
		}
Exemple #5
0
		/// <summary>
		/// adds the collider to the physics system
		/// </summary>
		/// <param name="collider">Collider.</param>
		public static void addCollider( Collider collider )
		{
			_spatialHash.register( collider );
		}
Exemple #6
0
		/// <summary>
		/// returns all colliders that are intersected by collider.bounds expanded to incorporate deltaX/deltaY
		/// excluding the passed-in collider (self)
		/// </summary>
		/// <returns>The neighbors excluding self.</returns>
		/// <param name="collider">Collider.</param>
		public static IEnumerable<Collider> boxcastBroadphaseExcludingSelf( Collider collider, float deltaX, float deltaY, int layerMask = allLayers )
		{
			var colliderBounds = collider.bounds;
			var sweptBounds = colliderBounds.getSweptBroadphaseBounds( deltaX, deltaY );
			return _spatialHash.aabbBroadphase( ref sweptBounds, collider, layerMask );
		}
Exemple #7
0
		/// <summary>
		/// returns all colliders that are intersected by bounds excluding the passed-in collider (self).
		/// this method is useful if you want to create the swept bounds on your own for other queries
		/// </summary>
		/// <returns>The excluding self.</returns>
		/// <param name="collider">Collider.</param>
		/// <param name="bounds">Bounds.</param>
		public static IEnumerable<Collider> boxcastBroadphaseExcludingSelf( Collider collider, ref RectangleF rect, int layerMask = allLayers )
		{
			return _spatialHash.aabbBroadphase( ref rect, collider, layerMask );
		}
Exemple #8
0
		/// <summary>
		/// checks to see if this Collider with motion applied (delta movement vector) collides with collider. If it does, true will be
		/// returned and result will be populated with collision data.
		/// </summary>
		/// <returns><c>true</c>, if with was collidesed, <c>false</c> otherwise.</returns>
		/// <param name="collider">Collider.</param>
		/// <param name="motion">Motion.</param>
		/// <param name="result">Result.</param>
		public bool collidesWith( Collider collider, Vector2 motion, out CollisionResult result )
		{
			// alter the shapes position so that it is in the place it would be after movement so we can check for overlaps
			var oldPosition = shape.position;
			shape.position += motion;

			var didCollide = shape.collidesWithShape( collider.shape, out result );
			if( didCollide )
				result.collider = collider;

			// return the shapes position to where it was before the check
			shape.position = oldPosition;

			return didCollide;
		}
Exemple #9
0
		/// <summary>
		/// gets all the colliders that fall within the specified rect
		/// </summary>
		/// <returns>the number of Colliders returned</returns>
		/// <param name="rect">Rect.</param>
		/// <param name="results">Results.</param>
		/// <param name="layerMask">Layer mask.</param>
		public static int overlapRectangleAll( ref RectangleF rect, Collider[] results, int layerMask = allLayers )
		{
			Assert.isFalse( results.Length == 0, "An empty results array was passed in. No results will ever be returned." );
			return _spatialHash.overlapRectangle( ref rect, results, layerMask );
		}
Exemple #10
0
		/// <summary>
		/// updates the colliders position in the physics system. This essentially just removes then re-adds the Collider with its
		/// new bounds
		/// </summary>
		/// <param name="collider">Collider.</param>
		public static void updateCollider( Collider collider )
		{
			_spatialHash.remove( collider );
			_spatialHash.register( collider );
		}
Exemple #11
0
		/// <summary>
		/// removes the collider from the physics system
		/// </summary>
		/// <returns>The collider.</returns>
		/// <param name="collider">Collider.</param>
		public static void removeCollider( Collider collider )
		{
			_spatialHash.remove( collider );
		}
Exemple #12
0
		public override void onAddedToEntity()
		{
			_collider = entity.getComponent<Collider>();
		}
Exemple #13
0
 /// <summary>
 /// checks to see if this Collider collides with collider. If it does, true will be returned and result will be populated
 /// with collision data
 /// </summary>
 /// <returns><c>true</c>, if with was collidesed, <c>false</c> otherwise.</returns>
 /// <param name="collider">Collider.</param>
 /// <param name="result">Result.</param>
 public bool collidesWith( Collider collider, out CollisionResult result )
 {
     return shape.collidesWithShape( collider.shape, out result );
 }
Exemple #14
0
		internal void reset()
		{
			collider = null;
			fraction = distance = 0f;
		}
Exemple #15
0
		/// <summary>
		/// checks to see if this shape overlaps any other Colliders in the Physics system
		/// </summary>
		/// <param name="collider">Collider.</param>
		public bool overlaps( Collider other )
		{
			return shape.overlaps( other.shape );
		}
Exemple #16
0
		/// <summary>
		/// checks to see if this Collider collides with collider. If it does, true will be returned and result will be populated
		/// with collision data
		/// </summary>
		/// <returns><c>true</c>, if with was collidesed, <c>false</c> otherwise.</returns>
		/// <param name="collider">Collider.</param>
		/// <param name="result">Result.</param>
		public bool collidesWith( Collider collider, out CollisionResult result )
		{
			if( shape.collidesWithShape( collider.shape, out result ) )
			{
				result.collider = collider;
				return true;
			}
			return false;
		}
Exemple #17
0
		/// <summary>
		/// gets all the colliders that fall within the specified circle
		/// </summary>
		/// <returns>the number of Colliders returned</returns>
		/// <param name="center">Center.</param>
		/// <param name="radius">Radius.</param>
		/// <param name="results">Results.</param>
		/// <param name="layerMask">Layer mask.</param>
		public static int overlapCircleAll( Vector2 center, float radius, Collider[] results, int layerMask = allLayers )
		{
			Assert.isFalse( results.Length == 0, "An empty results array was passed in. No results will ever be returned." );
			return _spatialHash.overlapCircle( center, radius, results, layerMask );
		}
Exemple #18
0
		void updateFollow()
		{
			_desiredPositionDelta.X = _desiredPositionDelta.Y = 0;

			if( _cameraStyle == CameraStyle.LockOn )
			{
				var targetX = _targetEntity.transform.position.X;
				var targetY = _targetEntity.transform.position.Y;

				// x-axis
				if( _worldSpaceDeadzone.x > targetX )
					_desiredPositionDelta.X = targetX - _worldSpaceDeadzone.x;
				else if( _worldSpaceDeadzone.x < targetX )
					_desiredPositionDelta.X = targetX - _worldSpaceDeadzone.x;

				// y-axis
				if( _worldSpaceDeadzone.y < targetY )
					_desiredPositionDelta.Y = targetY - _worldSpaceDeadzone.y;
				else if( _worldSpaceDeadzone.y > targetY )
					_desiredPositionDelta.Y = targetY - _worldSpaceDeadzone.y;
			}
			else
			{
				// make sure we have a targetCollider for CameraWindow. If we dont bail out.
				if( _targetCollider == null )
				{
					_targetCollider = _targetEntity.getComponent<Collider>();
					if( _targetCollider == null )
						return;
				}
				
				var targetBounds = _targetEntity.getComponent<Collider>().bounds;
				if( !_worldSpaceDeadzone.contains( targetBounds ) )
				{
					// x-axis
					if( _worldSpaceDeadzone.left > targetBounds.left )
						_desiredPositionDelta.X = targetBounds.left - _worldSpaceDeadzone.left;
					else if( _worldSpaceDeadzone.right < targetBounds.right )
						_desiredPositionDelta.X = targetBounds.right - _worldSpaceDeadzone.right;

					// y-axis
					if( _worldSpaceDeadzone.bottom < targetBounds.bottom )
						_desiredPositionDelta.Y = targetBounds.bottom - _worldSpaceDeadzone.bottom;
					else if( _worldSpaceDeadzone.top > targetBounds.top )
						_desiredPositionDelta.Y = targetBounds.top - _worldSpaceDeadzone.top;
				}
			}
		}
Exemple #19
0
		/// <summary>
		/// returns all colliders with bounds that are intersected by collider.bounds excluding the passed-in collider (self)
		/// </summary>
		/// <returns>The neighbors excluding self.</returns>
		/// <param name="collider">Collider.</param>
		public static IEnumerable<Collider> boxcastBroadphaseExcludingSelf( Collider collider, int layerMask = allLayers )
		{
			var bounds = collider.bounds;
			return _spatialHash.aabbBroadphase( ref bounds, collider, layerMask );
		}