Esempio n. 1
0
void Player::DoCollision() {
	if (noclip) return;
	Vector3I up = playerUp;
	bool X, Y, Z;
	X = Y = Z = true;

	Vector3D vel = FromWorld(this->vel);

	if (Game::world->Intersects(BBox().Offset(ToWorld(vel.X())))) {
		vel.x = 0;
		X = false;
	}
	if (Game::world->Intersects(BBox().Offset(ToWorld(vel.Y())))) {
		vel.y = 0;
		Y = false;
	}
	if (Game::world->Intersects(BBox().Offset(ToWorld(vel.Z())))) {
		inAir = vel.z > 0;
		vel.z = 0;
		Z = false;
	} else {
		inAir = true;
	}

	Vector3D avel = vel.Abs();


	if (X && Y && Z && Game::world->Intersects(BBox().Offset(this->vel))) {
		if (avel.x < avel.y && avel.x < avel.z) {
			vel.x = 0;
		} else if (avel.y < avel.z) {
			vel.y = 0;
		} else {
			vel.z = 0;
		}
	} else if (X && Y && Game::world->Intersects(BBox().Offset(ToWorld(vel.XY())))) {
		if (avel.x < avel.y) {
			vel.x = 0;
		} else {
			vel.y = 0;
		}
	} else if (X && Z && Game::world->Intersects(BBox().Offset(ToWorld(vel.XZ())))) {
		if (avel.x < avel.z) {
			vel.x = 0;
		} else {
			vel.z = 0;
		}
	} else if (Y && Z && Game::world->Intersects(BBox().Offset(ToWorld(vel.YZ())))) {
		if (avel.y < avel.z) {
			vel.y = 0;
		} else {
			vel.z = 0;
		}
	}

	this->vel = ToWorld(vel);
}