]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/creature.cpp
remove ability to fly at will
[blobs.git] / src / creature / creature.cpp
index 72d0b3f348e3c548ba55f6dcc00c52c6694408af..b609fe8a169c35462622a65aee816c17b4d8e077 100644 (file)
@@ -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;
        }