Skip to content

Commit

Permalink
Avoid rotating frame when starting in orbit
Browse files Browse the repository at this point in the history
If you create a ship in a rotating frame corresponding to a body, in the
very next (time) frame it will be thrown into a non-rotating frame, and
the ship's speed will be changed, which will lead to a deviation of the
orbit from circular.

Also use body data for the orbital radius and not the system body, so as
not to accidentally fall under the terrain. For example, this sometimes
happened on Phobos.
  • Loading branch information
Gliese852 committed Jan 11, 2024
1 parent 89fc2fe commit f50a50e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ Game::Game(const SystemPath &path, const double startDateTime, const char *shipT

m_space->AddBody(m_player.get());

m_player->SetFrame(b->GetFrame());

if (b->GetType() == ObjectType::SPACESTATION) {
m_player->SetFrame(b->GetFrame());
m_player->SetDockedWith(static_cast<SpaceStation *>(b), 0);
} else {
auto f = Frame::GetFrame(b->GetFrame());
if (f->IsRotFrame()) {
m_player->SetFrame(f->GetParent());
} else {
m_player->SetFrame(b->GetFrame());
}
// random orbit
// Taken from: LuaSpace.cpp, _orbital_velocity_random_direction()
const SystemBody *sbody = b->GetSystemBody();
vector3d pos{ MathUtil::RandomPointOnSphere(1.2 * sbody->GetRadius()) };
vector3d pos{ MathUtil::RandomPointOnSphere(1.2 * b->GetPhysRadius()) };
// calculating basis from radius - vector
vector3d k = pos.Normalized();
vector3d i;
Expand Down

0 comments on commit f50a50e

Please sign in to comment.