public bool Intersects(Vector3 destination) { //Get the colliders bool Intersected = false; BoundingBox newCollider = _coll.Offset(destination); Vector3Int MinBounds = Vector3Int.Floor(newCollider.Min); Vector3Int MaxBounds = Vector3Int.Ceiling(newCollider.Max); //loop between all blocks the collider is in for (int x = MinBounds.X; x <= MaxBounds.X; x++) { for (int y = MinBounds.Y; y <= MaxBounds.Y; y++) { for (int z = MinBounds.Z; z <= MaxBounds.Z; z++) { Intersected = Intersected || TestIntersection(new Vector3Int(x, y, z), newCollider); //Exit the loop if we collided, these are all extra iterations if (Intersected) { return(Intersected); } } //Exit the loop if we collided, these are all extra iterations if (Intersected) { return(Intersected); } } //Exit the loop if we collided, these are all extra iterations if (Intersected) { return(Intersected); } } return(Intersected); }
/// <summary> /// Moves the entity to the specified location in the time given. /// </summary> /// <param name="destination"></param> /// <param name="time"></param> public void PhysicsMove(Vector3 destination, float time, Color debugColor, bool checkGroundedness, bool Xmove, bool Ymove, Entity[] neighbouringEntities) { if (time == Time.PhysicsDeltaTime) { //Get the colliders bool Intersected = false, Grounded = false; BoundingBox newCollider = _coll.Offset(destination); Vector3Int MinBounds = Vector3Int.Floor(newCollider.Min); Vector3Int MaxBounds = Vector3Int.Ceiling(newCollider.Max); float axisPoint = 0; float axis = 0; //TEMP VAR for (int x = MinBounds.X; x <= MaxBounds.X; x++) { for (int y = MinBounds.Y; y <= MaxBounds.Y; y++) { for (int z = MinBounds.Z; z <= MaxBounds.Z; z++) { //Intersection test if (Xmove) { Intersected = Intersected || TestIntersectionX(new Vector3Int(x, y, z), newCollider, out axis); axisPoint = FastMath.ClosestToZero(axis, axisPoint); } else { if (Ymove) { if (checkGroundedness) { Grounded = Grounded || TestIntersectionY(new Vector3Int(x, y, z), newCollider, out axis); } Intersected = Intersected || TestIntersectionY(new Vector3Int(x, y, z), newCollider, out axis); axisPoint = FastMath.ClosestToZero(axis, axisPoint); } else { Intersected = Intersected || TestIntersectionZ(new Vector3Int(x, y, z), newCollider, out axis); axisPoint = FastMath.ClosestToZero(axis, axisPoint); } } //Exit the loop if we collided, these are all extra iterations if (Intersected) { break; } } //Exit the loop if we collided, these are all extra iterations if (Intersected) { break; } } //Exit the loop if we collided, these are all extra iterations if (Intersected) { break; } } //TODO: Entity intersections if (GameSettings.Debug.RenderPhysicsTestLocations) { //Entity Collider RenderUtils.DebugRenderBox(newCollider, debugColor, GameSettings.BlockOutlineWidth); } //GameClient.LOGGER.debug(-1, "======================================="); //Check for intersecting bounding boxes if (EnablePhysics) { if (Intersected == false) { //GameClient.LOGGER.debug(-1, "intersected: " + Intersected); //No intersection. Move the entity position = destination; } else { if (!IsGrounded) { //Intersection. Add axis point to the corresponding axis //Convert axisPoint to a Vector3 if (Xmove) { position.X += axisPoint; } else { if (Ymove) { position.Y += axisPoint; } else { position.Z += axisPoint; } } } } } else if (!EnablePhysics) { //Move the entity position = destination; } if (checkGroundedness && Ymove) { //Check for y IsGrounded = Grounded; } } }