Ashlar checks / tooling (push) Successful in 5s
New [Game] mantling setting, on by default, with mantle max height (1.1 times the actor's height above its feet) and mantle duration (0.4 s). When the player jumps or falls into a wall while moving towards it (within 60 degrees), the movement solver casts the player's collision shape up, across the edge and down. If it finds a surface flat enough to stand on, above the feet and within reach, with headroom and room on top, the player moves up, across and onto it along that checked path. Movement and jump input are ignored meanwhile, and the climb ends any fall without fall damage. No animation is needed. A script move or teleport, noclip or paralysis cancels a climb. Lua: self.controls.mantle (true by default) vetoes climbs while false, and the actor's scripts get an AshlarMantle event with the ledge height when one starts. The engine logs "Ashlar mantle:" lines at verbose level. Player only; with the setting off nothing changes. The geometry rules (reach, headroom, room on top, slope, too high, too low) and the climb path are in mwphysics/mantle.cpp, apart from the physics calls, with unit tests. The new mantle scenario uses a CC0 box mesh written for it: the player climbs an 80 unit ledge, doesn't climb it with the Lua veto, and doesn't climb a 240 unit wall. Closes #28 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
4.3 KiB
C++
96 lines
4.3 KiB
C++
#ifndef OPENMW_MWPHYSICS_MANTLE_H
|
|
#define OPENMW_MWPHYSICS_MANTLE_H
|
|
|
|
#include <osg/Vec3f>
|
|
|
|
// Ashlar ledge mantling ([Game] mantling). The geometry rules live here, apart from the physics calls, so that they
|
|
// can be unit tested. MovementSolver runs the shape casts and feeds their results to evaluate().
|
|
namespace MWPhysics::Mantle
|
|
{
|
|
/// Extra height the probe rises above the reachable ledge height, and the clearance kept over a ledge while
|
|
/// moving across it.
|
|
constexpr float sClearance = 4.f;
|
|
/// Smallest rise the probe needs before it can look for a ledge at all.
|
|
constexpr float sMinRise = 8.f;
|
|
/// A found surface has to be at least this far above the feet to count as a ledge.
|
|
constexpr float sMinHeight = 2.f;
|
|
/// Cosine of the widest angle between the movement and the way into the wall that still counts as pushing into
|
|
/// it (60 degrees).
|
|
constexpr float sMinPushCos = 0.5f;
|
|
|
|
/// Per-frame inputs decided on the main thread.
|
|
struct Params
|
|
{
|
|
bool mCanStart = false; ///< setting on, player, not vetoed by Lua, able to act
|
|
float mMaxHeightFactor = 1.1f; ///< highest ledge, as a multiple of the actor's height above its feet
|
|
float mDuration = 0.4f; ///< seconds a mantle takes
|
|
};
|
|
|
|
/// A mantle in progress. Positions are collision shape centres in world space.
|
|
struct State
|
|
{
|
|
bool mActive = false;
|
|
osg::Vec3f mStart;
|
|
float mPeakZ = 0.f; ///< height of the move across the ledge
|
|
osg::Vec3f mTarget;
|
|
osg::Vec3f mLast; ///< where the last step put the actor, to notice scripted moves
|
|
float mElapsed = 0.f;
|
|
float mDuration = 0.4f;
|
|
float mHeight = 0.f; ///< ledge height above the feet when it started
|
|
};
|
|
|
|
/// Whether the actor is trying to climb: in the air, pushing horizontally into a wall.
|
|
/// @param moveDir horizontal movement direction in world space (need not be normalized)
|
|
/// @param wallNormal normal of the wall that was hit, pointing towards the actor
|
|
bool wantsMantle(bool onGround, bool flying, bool underwater, const osg::Vec3f& moveDir,
|
|
const osg::Vec3f& wallNormal);
|
|
|
|
/// Horizontal unit direction into the wall, or a zero vector if the wall normal has no horizontal part.
|
|
osg::Vec3f intoWall(const osg::Vec3f& wallNormal);
|
|
|
|
/// How far up the probe rises, from the shape centre.
|
|
float probeRise(float actorHeight, float maxHeightFactor);
|
|
|
|
enum class Result
|
|
{
|
|
Ok,
|
|
NoHeadroom, ///< something above the actor stops it rising
|
|
Blocked, ///< the wall goes on above the reach, or there is no room on top for the actor
|
|
NoSurface, ///< nothing to stand on beyond the edge
|
|
Steep, ///< the surface on top is too steep to stand on
|
|
TooLow, ///< the surface isn't above the feet; ordinary stepping or falling handles it
|
|
TooHigh, ///< the surface is above the reach
|
|
};
|
|
|
|
const char* resultName(Result result);
|
|
|
|
/// What the three shape casts found.
|
|
struct Probe
|
|
{
|
|
float mFeetZ = 0.f; ///< current feet height
|
|
float mActorHeight = 0.f;
|
|
float mMaxHeightFactor = 1.1f;
|
|
float mRiseReached = 0.f; ///< how far the shape rose before hitting anything (up to probeRise)
|
|
float mForwardNeeded = 0.f; ///< how far the shape must move across the edge
|
|
float mForwardReached = 0.f; ///< how far it moved before hitting anything
|
|
bool mSurfaceHit = false; ///< whether the cast down found something
|
|
float mSurfaceFeetZ = 0.f; ///< feet height standing on the found surface
|
|
osg::Vec3f mSurfaceNormal{ 0.f, 0.f, 1.f };
|
|
};
|
|
|
|
Result evaluate(const Probe& probe);
|
|
|
|
/// Position along the mantle path: straight up from the start to the peak height, across to above the target,
|
|
/// then down onto it. The path is split by length, and progress eases in and out.
|
|
/// @param fraction 0 at the start, 1 at the end; clamped
|
|
osg::Vec3f pathPosition(const osg::Vec3f& start, float peakZ, const osg::Vec3f& target, float fraction);
|
|
|
|
/// Starts a mantle.
|
|
State start(const osg::Vec3f& start, float peakZ, const osg::Vec3f& target, float duration, float height);
|
|
|
|
/// Advances a mantle by dt and returns the new position. Ends it (mActive false) once it reaches the target.
|
|
osg::Vec3f advance(State& state, float dt);
|
|
}
|
|
|
|
#endif
|