-- name: Eje Invertido y Vuelo Libre
-- description: Eje Y normalizado (Arriba=Subir) para vuelo y nado. Presiona L para alternar la Capa Alada.
local FLIGHT_SPEED = 30.0 -- Velocidad horizontal de vuelo
local ASCEND_SPEED = 20.0 -- Velocidad vertical de vuelo
local SWIM_UP_SPEED = 15.0 -- Fuerza para subir/bajar nadando
-- Variable para registrar si el botón L ya fue presionado (evita bucles rápidos)
local lButtonPressed = false
hook_event(HOOK_MARIO_UPDATE, function(m)
-- Solo aplicar cambios al jugador local
if m.playerIndex ~= 0 then return end
-------------------------------------------------------------------------
-- 1. CONTROL DE LA CAPA ALADA CON EL BOTÓN L
-------------------------------------------------------------------------
if (m.controller.buttonPressed & L_TRIG) ~= 0 then
if not lButtonPressed then
lButtonPressed = true
-- Si ya tiene la capa, se la quitamos; si no la tiene, se la ponemos
if (m.flags & MARIO_WING_CAP) ~= 0 then
m.flags = m.flags & ~MARIO_WING_CAP
m.capTimer = 0
-- Si estaba volando, cancelamos el estado de vuelo al quitar la capa
if m.action == ACT_FLYING then
m.action = ACT_FREE_FALL
end
play_sound(SOUND_MENU_CAMERA_ZOOM_OUT, m.marioObj.header.gfx.cameraToObject)
else
m.flags = m.flags | MARIO_WING_CAP
m.capTimer = 9000 -- Tiempo extendido para que no expire sola
play_sound(SOUND_MENU_CAMERA_ZOOM_IN, m.marioObj.header.gfx.cameraToObject)
end
end
else
lButtonPressed = false
end
-------------------------------------------------------------------------
-- 2. VUELO LIBRE CON EJE Y RECTO (Arriba = Subir, Abajo = Bajar)
-------------------------------------------------------------------------
if (m.flags & MARIO_WING_CAP) ~= 0 then
-- Activar vuelo si está en el aire o intentando planear
if m.action == ACT_FLYING or (m.action & ACT_FLAG_AIR) ~= 0 then
m.action = ACT_FLYING
-- Eliminar la gravedad nativa
m.vel.y = 0
m.peakHeight = m.pos.y
-- Movimiento horizontal con Joystick
if m.intendedMag > 0 then
m.faceAngle.yaw = m.intendedYaw
m.forwardVel = FLIGHT_SPEED
else
m.forwardVel = 0
end
-- EJE Y MODIFICADO: Mover palanca arriba (stickY positivo) SUBE a Mario
if m.controller.stickY ~= 0 then
local stickYNormalized = m.controller.stickY / 64.0
m.pos.y = m.pos.y + (stickYNormalized * ASCEND_SPEED)
-- Inclinar visualmente hacia arriba o abajo según la palanca
m.faceAngle.pitch = math.floor(-stickYNormalized * 0x1800)
else
m.faceAngle.pitch = 0
end
-- Mantener animación estable de vuelo
set_mario_animation(m, MARIO_ANIM_WING_CAP_FLY)
end
end
-------------------------------------------------------------------------
-- 3. NADO CON EJE Y RECTO (Arriba = Nadar hacia la superficie)
-------------------------------------------------------------------------
if (m.action & ACT_FLAG_SWIMMING) ~= 0 then
-- Si se empuja la palanca hacia arriba, sumamos velocidad vertical positiva
if m.controller.stickY > 0 then
local stickYNormalized = m.controller.stickY / 64.0
m.vel.y = stickYNormalized * SWIM_UP_SPEED
m.faceAngle.pitch = math.floor(-stickYNormalized * 0x1500)
-- Si se empuja hacia abajo, restamos velocidad para sumergirse de frente
elseif m.controller.stickY < 0 then
local stickYNormalized = m.controller.stickY / 64.0
m.vel.y = stickYNormalized * SWIM_UP_SPEED
m.faceAngle.pitch = math.floor(-stickYNormalized * 0x1500)
end
end
end)
To embed this project on your website, copy the following code and paste it into your website's HTML: