X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fcreature%2Fcreature.cpp;h=b609fe8a169c35462622a65aee816c17b4d8e077;hp=72d0b3f348e3c548ba55f6dcc00c52c6694408af;hb=96b12298b5aacfdd8564eb3eeff7fef453b9c8a0;hpb=00f55d5b55ff993d2516f00f8d635887562983c7 diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index 72d0b3f..b609fe8 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -927,6 +927,10 @@ bool Situation::OnSurface() const noexcept { return type == PLANET_SURFACE; } +bool Situation::OnGround() const noexcept { + return OnSurface() && glm::length2(state.pos) < (planet->Radius() + 0.05) * (planet->Radius() + 0.05); +} + glm::dvec3 Situation::SurfaceNormal() const noexcept { return planet->NormalAt(state.pos); } @@ -1059,6 +1063,10 @@ glm::dvec3 Steering::Force(const Situation::State &s) const noexcept { result += TargetVelocity(s, diff * std::min(dist * force, speed) / dist, force); } } + // remove vertical component, if any + const glm::dvec3 normal(c.GetSituation().GetPlanet().NormalAt(s.pos)); + result += normal * glm::dot(normal, result); + // clamp to max if (glm::length2(result) > max_force * max_force) { result = glm::normalize(result) * max_force; }