Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

the current speed to affect headbob after?

Asked by 1 year ago

my script is

01local runService = game:GetService("RunService") -- Runs something every single frame
02local currentSpeed = 0
03local character = script.Parent -- this script will be in the actual player because its in StarterPlayerScripts
04local pos = character.HumanoidRootPart.Position
05local humanoid = character:WaitForChild("Humanoid") -- wait for child because we dont want to index it if its not loaded yet as that would cause errors
06 
07function updateHeadBobble()
08    local currentTime = tick() -- tick(): gets current "epoc" time stamp
09    if humanoid.MoveDirection.Magnitude > 0 then -- Mangitude: The distance from 0 so if the magnitude is bigger than 0, the player is moving
10        pos = character.HumanoidRootPart.Position
11        wait(1)
12        currentSpeed = (pos-character.HumanoidRootPart.Position).magnitude
13        print(currentSpeed)
14        local bobbleX = math.cos(currentTime * 7.5) * currentSpeed -- bobbles in a cosine graph motion,an infinite ~
15        local bobbleY = math.abs(math.sin(currentTime * 7.5)) * currentSpeed -- bobbles in a sine graph motion, practically the same as cosine but a bit offset
View all 27 lines...

It works but it happens after i move but i want the headbob to happen whilst im moving Anyone got any idea???

Answer this question