Mouse speed and player character turning speed

I’m making a game with a top-down view and have a script to make the player turn towards the mouse.

The problem is the speed at which the mouse moves, the player turns way too fast. Is there any way to make the mouse move slower and in that way reduce the speed at which the player turns?

3 Likes

The only way I can think of making the “mouse move slower” to to use MouseDeltaSensitivity but the player could just turn the sensitivity up.

2 Likes

Use the :Lerp function when you are turning the player towards the mouse.

1 Like

I am familiar with the concept of lerp but not sure how to implement it in this script:

local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local root = character:WaitForChild(“HumanoidRootPart”)

local Mouse = Player:GetMouse()
local RunService = game:GetService(“RunService”)

RunService.RenderStepped:Connect(function()
local RootPos, MousePos = root.Position, Mouse.Hit.Position
root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
end)

The root.Cframe should be lerped, between where it is at and to where it is going. How would you do this?

local Game = game
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart") or Character:WaitForChild("HumanoidRootPart")

while true do
	local Time = 0
	while true do
		if Time > math.deg(math.pi / 2) then break end
		local Pivot = Character:GetPivot()
		local CF = CFrame.lookAt(Pivot.Position, Vector3.new(Mouse.Hit.X, Pivot.Y, Mouse.Hit.Z))
		Character:PivotTo(Pivot:Lerp(CF, Time / math.deg(math.pi / 2)))
		Time += RunService.RenderStepped:Wait()
	end
end
3 Likes

Hi,
First off; this definitely works so thank you so much for this! I’m marking this as the solution.
Second; I don’t fully understand the math part so I’ll take some time to learn and understand :wink:
Again, thank you!

Is there any way to insert a variable and use that to slow the turn speed further?
I am trying to understand the code and learn about this, I see lerp is being used for the turning in the PivotTo value and “Time / math.deg(math.pi / 2” is the value that determines the step in which you turn? Could this value be divided (with that variable) to become smaller and so making the turning slower or am I misinterpreting the meaning?

math.deg(math.pi / 2) is 180 so you could experiment with values 90 through 270.

1 Like