#animating with running

1 messages · Page 1 of 1 (latest)

mortal yacht
#

if i have a simple running script, how would I prevent the player from running backwards? Usually it works but there are special cases where if you do it right, running continues backwards.
Another thing is to have tools register with their own running animations, so how would I check if a tool is equipped in a constant loop?

Basically just a way to constantly update while maintaining performance

jagged idol
#

@mortal yacht are you using MoveDirection?

#

to currently fix the issue

mortal yacht
#

MoveDirection?

jagged idol
#

yes

mortal yacht
#

i need to check my original tihng

#

but i think i used enum.keycode (obv didnt work)

jagged idol
#

yeah lol

mortal yacht
#

ill have to research, since i've never seen it before lmao

jagged idol
#

i asked chatgpt and it gave me this

#

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")

local runThreshold = 0.9 -- Adjust this to control how strict forward running must be
local isRunning = false

game:GetService("RunService").RenderStepped:Connect(function()
    local moveDir = humanoid.MoveDirection
    if moveDir.Magnitude > 0.1 then
        local facingDir = hrp.CFrame.LookVector.Unit
        local dot = moveDir:Dot(facingDir)

        if dot >= runThreshold then
            -- Only allow running forward
            if not isRunning then
                isRunning = true
                -- play run animation or trigger running
            end
        else
            if isRunning then
                isRunning = false
                -- stop run animation or revert to walk
            end
        end
    else
        if isRunning then
            isRunning = false
            -- stop run animation
        end
    end
end)```
mortal yacht
#

ah, that would be wrong if tech, speaking then

jagged idol
#

wdym?

mortal yacht
#

movedirection.magnitude would call for the overall if moving

#

in a vector

#

if I'm right

jagged idol
#

yes

mortal yacht
#

so if you're moving backwords in relation to all 3d space, it would be >1

#

right?

#

hence all movement >1 unless idle

jagged idol
#

100% right

mortal yacht
#

darn

jagged idol
#

but

#

i found another soltuon

#

if you pair it with :Dot()

#
local RunService = game:GetService("RunService")

local function setup(character)
    local humanoid = character:WaitForChild("Humanoid")
    local rootPart = character:WaitForChild("HumanoidRootPart")

    RunService.RenderStepped:Connect(function()
        local moveDir = humanoid.MoveDirection
        if moveDir.Magnitude > 0 then
            local lookDir = rootPart.CFrame.LookVector
            local dot = moveDir:Dot(lookDir)

            -- Debug print
            -- print("Dot:", dot)

            if dot < -0.25 then
                -- BLOCK BACKWARDS
                humanoid.WalkSpeed = 0 -- or custom logic to disable run
            else
                humanoid.WalkSpeed = 16 -- restore normal speed
            end
        else
            humanoid.WalkSpeed = 16 -- idle = normal
        end
    end)
end

player.CharacterAdded:Connect(setup)
if player.Character then
    setup(player.Character)
end
#

it should do the trick

#

or even some form of combining movedirection with lookvector

mortal yacht
#

how?

mortal yacht
#

let me test it

jagged idol
mortal yacht
#

?

jagged idol
#

try this one cuz that one literally just stops moving if you go backwards

mortal yacht
#

ah

jagged idol
#

it wont let me send

mortal yacht
#

i need this also to only work when shiftlock is enabled, so cameralock yeah

#

i forget the var

jagged idol
#

prob Enum.CameraMode.LockFirstPerson

mortal yacht
jagged idol
#

yeah

#

im gonna try to send the code in two halves

mortal yacht
#

player.shiftlockwhatevercameratype == enum... blahs

#

ok

quartz bearBOT
#

studio** You are now Level 4! **studio

mortal yacht
#

you could use files, although

jagged idol
#

local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")

local function setup(character)
    -- Basic references
    local humanoid = character:WaitForChild("Humanoid")
    local rootPart = character:WaitForChild("HumanoidRootPart")
    
    -- Load a run animation (replace the AnimationId with yours)
    local runAnim = Instance.new("Animation")
    runAnim.AnimationId = "rbxassetid://<YOUR_RUN_ANIMATION_ASSET_ID>"  -- Set your run animation ID here
    local runAnimTrack = humanoid:LoadAnimation(runAnim)
    
    -- A flag to track if we want to run the animation
    local isRunning = false
    
    -- Using RenderStepped to check every frame
    RunService.RenderStepped:Connect(function()
        local moveDir = humanoid.MoveDirection
        -- Check if the player is inputting any move command
        if moveDir.Magnitude > 0 then
            local lookDir = rootPart.CFrame.LookVector
            local dot = moveDir:Dot(lookDir)
            
            -- If dot < -0.25, the movement is significantly backward.
            if dot < -0.25 then
                -- Block the run animation if it's playing.
#
                    runAnimTrack:Stop()
                end
                isRunning = false
            else
                -- Allow running forward or strafing
                if not isRunning then
                    isRunning = true
                    runAnimTrack:Play()
                end
            end
        else
            -- If no movement, ensure the run animation isn't playing.
            if runAnimTrack.IsPlaying then
                runAnimTrack:Stop()
            end
            isRunning = false
        end
    end)
end

-- Set up when the character spawns.
player.CharacterAdded:Connect(setup)
if player.Character then
    setup(player.Character)
end
jagged idol
mortal yacht
#

running plays without keybind w/ no speed boost lol

jagged idol
#

do you change the walkspeed?

#

or how do you apply the boost

mortal yacht
#

usually walkspeed ofc

#

lemme

jagged idol
#

perfect

#

just check walkspeed then

mortal yacht
#

yeah

#

now i gotta do keybinds

#

i gotta test it tho

jagged idol
#

kk

#

if anything lmk

mortal yacht
#

alrighty

#

also what is ur pfp 😭

jagged idol
#

lol its just cursed

mortal yacht
#

yeah, matches yo name lol

jagged idol
#

haha thank you i strive for that

mortal yacht
#

heyy it works!

jagged idol
#

booooomshakala

#

and they say chatgpt is useless

mortal yacht
#

yeah

#

gpt 4o has major upgrades

#

lowkey wouldn't figure out the math for the dot vector, only in eigth going on ninth grade lmao

jagged idol
mortal yacht
#

next i have to do a backpedal running

#

😭

jagged idol
#

reverse animation

#

ezpz

mortal yacht
#

i hate animation

jagged idol
#

same

mortal yacht
jagged idol
#

id just reverse animation and change the easing

#

oh true

mortal yacht
#

yeah

#

maybe ill just skip out on that lmao

#

now

#

how would I make it to where the animator script detects tools and reads a value under the tool to change the running animation to the right one?

mortal yacht
#

prol use num values

#

or strings lmao

#

also also also

jagged idol
#

yea

mortal yacht
#

how do i add tools to the roblox animator

#

never really tried

jagged idol
#

i think you just have to drop it in the character

mortal yacht
#

ah

jagged idol
#

whatever tool you wanna use

mortal yacht
#

ok

jagged idol
#

ye

mortal yacht
#

?

#

CAS?

royal blaze
#

Context Action Service

mortal yacht
#

ah

#

well, part of it has been solved, and as in part i mean fully. How do i close a ticketlol

jagged idol
#

or smth lol not sure

mortal yacht
#

weait

#

so there's some other issues ive ran into using cas