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?
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”)
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
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
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?