Enable falling through the planet

Falling through the planet basically behaves like falling through a
torus with a hole. There are no special visuals to it, it's basically
just teleporting to the other side of the planet and reversing the
vertical velocity.
master
Evert 2018-03-20 19:46:20 +02:00
parent e871b4a877
commit 2f188ddfc9
No known key found for this signature in database
GPG Key ID: 1688DA83D222D0B5
2 changed files with 18 additions and 2 deletions

View File

@ -395,6 +395,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("planet_keep_scale", "true");
settings->setDefault("planet_centrifugal_enable", "true");
settings->setDefault("planet_realistic_gravity", "false");
settings->setDefault("planet_fallthrough_enable", "true");
// Server list announcing
settings->setDefault("server_announce", "false");

View File

@ -1134,8 +1134,12 @@ void Game::handlePlanet() {
// Quick hack: Teleport to other side of planet at planet edges
if (g_settings->getBool("planet_enable")) {
// Round planet circumference up to even number of blocks, value in x/z coordinates
int planet_circumference = ceil(g_settings->getU16("planet_radius") * M_PI) * BS * MAP_BLOCKSIZE * 2;
int planet_radius = g_settings->getU16("planet_radius");
int planet_circumference = ceil(planet_radius * M_PI) * BS * MAP_BLOCKSIZE * 2;
v3f playerpos = player->getPosition();
// Teleport to other side of planet at planet edges
if (playerpos.X > planet_circumference / 2 - 0.5 * BS)
playerpos.X = -(float)planet_circumference / 2 - 0.5 * BS;
if (playerpos.X < -planet_circumference / 2 - 0.5 * BS)
@ -1145,8 +1149,19 @@ void Game::handlePlanet() {
if (playerpos.Z < -planet_circumference / 2 - 0.5 * BS)
playerpos.Z = (float)planet_circumference / 2 - 0.5 * BS;
// Falling through the planet. The point on the other side is defined as
// pos.X += circumference / 2, as if the planet was a torus.
if (g_settings->getBool("planet_fallthrough_enable")) {
if (playerpos.Y < -planet_radius * MAP_BLOCKSIZE * BS) {
playerpos.Y = -planet_radius * MAP_BLOCKSIZE * BS + BS;
playerpos.X += planet_circumference / 2. * (playerpos.X < 0 ? 1 : -1);
v3f playerspeed = player->getSpeed();
playerspeed.Y *= -1;
player->setSpeed(playerspeed);
}
}
m_planet_warp_changed = player->getPosition() != playerpos;
player->setPosition(playerpos);
}
}