Files
claudeandClaude Opus 5.5 f3bb0753c7
Ashlar checks / tooling (push) Successful in 6s
Add movement acceleration and deceleration
New [Game] movement acceleration setting, on by default, with
movement acceleration time (0.15 s), movement deceleration time (0.1 s)
and movement air control (0.3). Movement ramps towards the requested
movement in the actor's own frame, so turning is never delayed.
Reversing slows down through zero before speeding up the other way,
and sideways movement left over from a direction change dies away at
the deceleration rate. NPCs and creatures stop at once so they never
overshoot a path point. With the setting off, behavior is unchanged.

The ramp is in mwmechanics/movementramp.cpp with unit tests, including
frame-rate independence from 1/30 to 1/240 s. A new headless
SCENARIO=movement logs the player's speed as it starts, stops and
reverses.

Refs #26

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 03:35:19 -05:00

39 lines
1.9 KiB
C++

#ifndef OPENMW_MECHANICS_MOVEMENTRAMP_H
#define OPENMW_MECHANICS_MOVEMENTRAMP_H
#include <osg/Vec2f>
namespace MWMechanics
{
// Ashlar movement acceleration. With [Game] movement acceleration on, an actor's movement doesn't snap to full
// speed when a movement control is pressed or stop dead when it is released. The movement the character controller
// sends to physics ramps towards the requested movement instead. Movement is ramped in the actor's own frame
// (x to the right, y forward), so turning, by the mouse or by AI steering, is never delayed.
struct MovementRampTimes
{
/// Seconds to go from standing to full speed. 0 or less is instant.
float mAccelerationTime = 0.15f;
/// Seconds to go from full speed to standing. 0 or less is instant.
float mDecelerationTime = 0.1f;
};
/// Moves \a current towards \a target over \a dt seconds. Both are movement factors in the actor's frame, with a
/// length of 0 (standing) to 1 (full speed). The part of \a current along the target direction rises at
/// 1 / acceleration time and falls at 1 / deceleration time; the part across it falls at 1 / deceleration time.
/// Reversing direction therefore slows down through zero before speeding up the other way. The result doesn't
/// depend on how \a dt is split into frames while the target stays the same.
osg::Vec2f rampMovement(
const osg::Vec2f& current, const osg::Vec2f& target, float dt, const MovementRampTimes& times);
/// Acceleration and deceleration times from [Game] movement acceleration time and movement deceleration time,
/// scaled by [Game] movement air control when \a inAir (jumping or falling). An air control of 0 keeps the
/// movement from changing in the air.
MovementRampTimes getMovementRampTimes(bool inAir);
/// True if [Game] movement acceleration is on.
bool usesMovementAcceleration();
}
#endif