Make the player turn slower

im trying to make a system where when you press a button your character turns slower but I can’t figure out how, i’ve looked at a lot of different things to figure it out and I still can’t figure this out. I found something that might work but I’m kind of confused on it Any way to stop player's character from spinning too fast? - #3 by Jexemie is there any way I can get this to work?

lerp, detect cframe changes, and lerp at a point like 0.2

how would i do this, i haven’t used lerp yet.

explain your system further so i can help

I press a button then the player starts moving forward via body velocity and i want it to be so that while you’re moving forward when you turn you turn at a very slow rate regardless of if you’re shiftlocked or not.

does the body velocity constantly use players lookVector?

yes it does. i want it so when you turn it turns slower

in your loop i’d be something like this then
BodyVelocity.Velocity = BodyVelocity.Velocity:Lerp(FinalRotation, 0.2) * dt

heres a way to do it

-- IN A LOCAL SCRIPT!!!

local player = game.Players.LocalPlayer
local character = player.Character
local camera = workspace.CurrentCamera
local hrp = character:FindFirstChild("HumanoidRootPart")
local hum = character:FindFirstChild("Humanoid")

hum.AutoRotate = false -- this makes it so the character wont instantly turn when you're in first person/shiftlock

local attachment = Instance.new("Attachment")
attachment.Parent = hrp
local align = Instance.new("AlignOrientation")
align.Mode = Enum.OrientationAlignmentMode.OneAttachment
align.Responsiveness = 10 -- higher the number, the faster it makes the humanoid root part turn
align.MaxTorque = math.huge
align.Parent = hrp
align.Attachment0 = attachment

-- if you want to later disable the drifted turning, create a variable for it (i suggest you name it [something]Conn or just conn)

local conn = game:GetService("RunService").RenderStepped:Connect(function()
    local camDirection = Vector3.new(camera.CFrame.LookVector.X, 0, camera.CFrame.LookVector.Z).Unit -- this doesnt take into account if the camera is looking up or down
    local currentLook = Vector3.new(hrp.CFrame.LookVector.X, 0, hrp.CFrame.LookVector.Z).Unit -- this is the direction the humanoid root part is currently facing
    local angle = math.acos(currentLook:Dot(camDirection))
    
    if angle > 0.1 then -- this is just to avoid updating every frame for better performance and stability
        local newCFrame = CFrame.lookAt(hrp.Position, hrp.Position + camDirection)
        align.CFrame = newCFrame
    end
end)

-- to disable this later, just do:
conn:Disconnect() -- disables the function the variable is connected to
humanoid.AutoRotate = true -- re-enables instant turning with shiftlock and first person

i think it should work im pretty sure
if you need any extra info then feel free to ask!!

1 Like

just a question, what would “FinalRotation” and “dt” be set as?

dt is deltaTime - time between each frame, you can get this from any RunService loop parameters.

RunService.PreRender:Connect(function(dt)

end)

and FinalRotation would just be the rotation you are to set, but instead of directly setting it, you lerp it.
For example:
If you have range 0-10, and FinalNumber is 10, instead of doing something like Number.Value = 10
you would get a specific point of it Number.Value:lerp(10, 0.2) which is 20% of 10 so 2, but ignore that I used lerp on number value it’s just an example

I cant get it to work
how exactly do i get dt?

local dt = 0

local RunService = game:GetService("RunService")

RunService.PreRender:Connect(function(dt)
	dt = dt
end)

you dont need to create a variable for deltatime, its automatically provided as a parameter when you connect a function to RunService.Renderstepped or Heartbeat

Not sure what you’re doing here totally.. I have a gun system I was testing turning on.
This one can go so slow speed 1 it’s too slow.. 8 seems fine.

--LocalScript in StarterCharacterScripts
task.wait(1)

local player = game.Players.LocalPlayer
local rs = game:GetService("RunService")
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera

hum.AutoRotate = false

rs.RenderStepped:Connect(function(dt)
	local camDir = Vector3.new(camera.CFrame.LookVector.X,0,camera.CFrame.LookVector.Z).Unit
	local target = CFrame.lookAt(hrp.Position, hrp.Position + camDir)

	local maxSpin = 8
	local angVel = hrp.AssemblyAngularVelocity

	if angVel.Magnitude > maxSpin then
		hrp.AssemblyAngularVelocity = angVel.Unit * maxSpin
	end

	hrp.CFrame = hrp.CFrame:Lerp(target, dt * maxSpin)
end)

This is for a locked cam however.. Idk if it will work for you, but has a lot of what you’re talking about here in it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.