Hello everyone!
So i’m making a horror game with monsters, and rigs are moving kinda too sharply, including the players.
To fix this i found a code that gets move vector from player module and makes player move smoothly, but the problem is that i couldn’t edit this script like that so it works on server script with rig (not player).
Here is script (that is currently works on client side only with player, i don’t know with what i should change the variables so it works on server):
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local camera = game.Workspace.CurrentCamera
local RunS = game:GetService("RunService")
local targetMoveVelocity = Vector3.new()
local moveVelocity = Vector3.new()
local moveAcceleration = character:WaitForChild("Humanoid"):GetAttribute("MoveAcceleration")
local function lerp(a, b, t) return a + (b - a) * t end
local function getWalkDirectionCameraSpace()
local walkDir = require(plr:WaitForChild("PlayerScripts").PlayerModule:WaitForChild("ControlModule")):GetMoveVector()
if walkDir.Magnitude > 0 then
walkDir = walkDir.Unit
end
return walkDir
end
local function getWalkDirectionWorldSpace()
local walkDir = camera.CFrame:VectorToWorldSpace(getWalkDirectionCameraSpace())
walkDir *= Vector3.new(1, 0, 1) --Set Y axis to 0
if walkDir.Magnitude > 0 then
walkDir = walkDir.Unit
end
return walkDir
end
local function updateMovement(dt)
moveAcceleration = character:WaitForChild("Humanoid"):GetAttribute("MoveAcceleration")
local humanoid = character:FindFirstChild("Humanoid")
local HRP = character:FindFirstChild("HumanoidRootPart")
if humanoid then
local moveDir = getWalkDirectionWorldSpace()
targetMoveVelocity = moveDir
moveVelocity = lerp(moveVelocity, targetMoveVelocity, math.clamp(dt * moveAcceleration, 0, 1))
humanoid:Move(moveVelocity)
end
end
RunS.RenderStepped:Connect(updateMovement)
Every time i tried to find a script that would make dummy walk smoothly it would just give me how to make dummy turn smoothly or just begginer tutorial how to make dummy walk.
I want dummy to slowly accelerate when he starts walking and slowly decelerate when he stops and the speed would depend on the moveAccelerating variable, and no i don’t want just to change walkspeed beacuse when dummy would already accelerate go other direction he would do it instantly (not smooth).
Dummy should turn other directions smoothly too.
Can somebody help me please?