Nez.Mover.move C# (CSharp) Méthode

move() public méthode

moves the entity taking collisions into account
public move ( Vector2 motion, CollisionResult &collisionResult ) : bool
motion Microsoft.Xna.Framework.Vector2 Motion.
collisionResult CollisionResult Collision result.
Résultat bool
		public bool move( Vector2 motion, out CollisionResult collisionResult )
		{
			collisionResult = new CollisionResult();

			// no collider? just move and forget about it
			if( entity.getComponent<Collider>() == null || _triggerHelper == null )
			{
				entity.transform.position += motion;
				return false;
			}

			// 1. move all non-trigger Colliders and get closest collision
			var colliders = entity.getComponents<Collider>();
			for( var i = 0; i < colliders.Count; i++ )
			{
				var collider = colliders[i];

				// skip triggers for now. we will revisit them after we move.
				if( collider.isTrigger )
					continue;

				// fetch anything that we might collide with at our new position
				var bounds = collider.bounds;
				bounds.x += motion.X;
				bounds.y += motion.Y;
				var neighbors = Physics.boxcastBroadphaseExcludingSelf( collider, ref bounds, collider.collidesWithLayers );

				foreach( var neighbor in neighbors )
				{
					// skip triggers for now. we will revisit them after we move.
					if( neighbor.isTrigger )
						continue;

					if( collider.collidesWith( neighbor, motion, out collisionResult ) )
					{
						// hit. back off our motion
						motion -= collisionResult.minimumTranslationVector;
					}
				}
			}
			ListPool<Collider>.free( colliders );

			// 2. move entity to its new position if we have a collision else move the full amount. motion is updated when a collision occurs
			entity.transform.position += motion;

			// 3. do an overlap check of all Colliders that are triggers with all broadphase colliders, triggers or not.
			//    Any overlaps result in trigger events.
			_triggerHelper.update();

			return collisionResult.collider != null;
		}
	}