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>
102 lines
3.4 KiB
Lua
102 lines
3.4 KiB
Lua
-- Ashlar headless mantle scenario (CC0). The player runs at a test ledge and jumps, three times:
|
|
-- mantle a ledge 80 units high: the player must climb it and end up on top
|
|
-- veto the same ledge with self.controls.mantle = false: no climb
|
|
-- toohigh the ledge scaled into a 240 unit wall: no climb
|
|
-- Each phase starts by putting the player back at the start. The engine logs "Ashlar mantle:" lines at verbose
|
|
-- level, and this script logs AshlarMantle events and where the player ends up.
|
|
local core = require('openmw.core')
|
|
local self = require('openmw.self')
|
|
local I = require('openmw.interfaces')
|
|
|
|
local PHASES = {
|
|
{ name = 'settle', at = 0 },
|
|
{ name = 'mantle', at = 2, distance = 150, scale = 1, mantle = true },
|
|
{ name = 'veto', at = 8, distance = 150, scale = 1, mantle = false },
|
|
{ name = 'toohigh', at = 14, distance = 330, scale = 3, mantle = true },
|
|
{ name = 'done', at = 20 },
|
|
}
|
|
|
|
local t = 0
|
|
local applied = 0
|
|
local phase
|
|
local start
|
|
local events = 0
|
|
local peak = 0
|
|
local climbed
|
|
|
|
local function log(fmt, ...)
|
|
print('ASHLAR_MANTLE ' .. string.format(fmt, ...))
|
|
end
|
|
|
|
local function finishPhase()
|
|
if not phase or not phase.distance then
|
|
return
|
|
end
|
|
local dz = self.position.z - start.position.z
|
|
log('result %s events=%d peak=%.1f dz=%.1f', phase.name, events, peak, dz)
|
|
end
|
|
|
|
local function enterPhase(p)
|
|
finishPhase()
|
|
phase = p
|
|
applied = 0
|
|
events = 0
|
|
peak = 0
|
|
climbed = false
|
|
if p.distance then
|
|
core.sendGlobalEvent('AshlarMantleSetup', { player = self.object, start = start, distance = p.distance,
|
|
scale = p.scale })
|
|
end
|
|
log('phase %s', p.name)
|
|
end
|
|
|
|
return {
|
|
eventHandlers = {
|
|
AshlarMantle = function(e)
|
|
events = events + 1
|
|
climbed = true
|
|
log('event %s height=%.1f', phase and phase.name or '?', e.height)
|
|
end,
|
|
},
|
|
engineHandlers = {
|
|
onFrame = function(dt)
|
|
if dt <= 0 or (phase and phase.name == 'done') then
|
|
return
|
|
end
|
|
if not phase then
|
|
I.Controls.overrideMovementControls(true)
|
|
I.Controls.overrideCombatControls(true)
|
|
start = { position = self.position, rotation = self.rotation }
|
|
enterPhase(PHASES[1])
|
|
end
|
|
t = t + dt
|
|
local nextPhase = phase
|
|
for _, p in ipairs(PHASES) do
|
|
if t >= p.at then
|
|
nextPhase = p
|
|
end
|
|
end
|
|
if nextPhase ~= phase then
|
|
enterPhase(nextPhase)
|
|
end
|
|
|
|
-- Skip the first moments, before the teleport back to the start has happened.
|
|
if phase.distance and applied >= 0.3 then
|
|
peak = math.max(peak, self.position.z - start.position.z)
|
|
end
|
|
-- Run at the ledge after a moment to settle, jumping every half second, until a climb starts.
|
|
local go = phase.distance ~= nil and applied >= 0.5 and not climbed
|
|
self.controls.movement = go and 1 or 0
|
|
self.controls.sideMovement = 0
|
|
self.controls.run = true
|
|
self.controls.jump = go and (applied % 0.5) < dt
|
|
self.controls.yawChange = 0
|
|
self.controls.use = 0
|
|
if phase.mantle ~= nil then
|
|
self.controls.mantle = phase.mantle
|
|
end
|
|
applied = applied + dt
|
|
end,
|
|
},
|
|
}
|