My Dive ability isnt working and i dont know how to fix it

TWJESTER

Member
Reposting it in the right place this time lol, but can someone check out my code cuz it doesnt work for me

local lastJumpTime = 0 -- Tracks the last time the player pressed jump
local doubleTapTime = 0.5 -- Time window for double tap (in seconds)
local canDive = false -- Flag to track if dive is available

-- Function to start the dive
function StartDive(player)
if player.mo and player.mo.z > 0 then -- Ensure the player is in the air
-- Calculate forward movement based on the player's current momentum
local forwardSpeed = player.mo.vel.x * 1.5 -- Scale player's momentum for X-axis
local strafeSpeed = player.mo.vel.y * 1.5 -- Scale player's momentum for Y-axis

-- Debug output to check the velocities
print("Starting dive with X speed: ", forwardSpeed, " Y speed: ", strafeSpeed)

-- Apply forward momentum (move the player in the X and Y direction)
player.mo.vel.x = forwardSpeed
player.mo.vel.y = strafeSpeed

-- Apply a slight upward velocity to simulate a swoosh effect
player.mo.vel.z = 8 -- Slight vertical velocity to add momentum to the dive

-- Disable the dive ability until the player lands again
canDive = false
end
end

-- Function to check for double-tap
function CheckDoubleTap(player)
local currentTime = player.mo.time -- Get the current game time

-- Debug output to check jump presses
if player.cmd.buttons & BT_JUMP ~= 0 then
print("Jump button pressed")

if currentTime - lastJumpTime <= doubleTapTime then
print("Double tap detected!")
if canDive then
StartDive(player) -- Trigger the forward dive ability
end
else
lastJumpTime = currentTime -- Reset the time if it wasn't a double-tap
end
end
end

-- Function to reset dive ability when touching the ground
function ResetDive(player)
if player.mo.z == 0 then -- Check if the player is on the ground
print("Player is on the ground, resetting dive ability.")
canDive = true -- Re-enable the dive ability when the player touches the ground
end
end

-- Hook everything together
addHook("PlayerThink", function(player)
ResetDive(player) -- Reset dive if on the ground
CheckDoubleTap(player) -- Check for double tap to trigger dive
end)
 
Did you just ask an AI to write the code for you? I wouldn't recommend you to do that because the AI has partial knowledge on BLUA, which is the programming language used for SRB2 LUA scripts. That's why your script might not be working.
For example, one of the errors I noticed in the code is the use of decimal numbers, which is a thing that BLUA doesn't support.
 
Yeah, don't use generative AI. On top of being wrong a lot of the time (particularly about BLua, but also in general), it's also largely trained off of stolen work that was taken without the original creators' consent. If you still have the original script from before you gave it to ChatGPT, go back to that; it'll probably be easier to debug. If not, you might just have to start over.
 

Who is viewing this thread (Total: 0, Members: 0, Guests: 0)

Back
Top