the title explains it, i dont mean i want the characters arm to follow the mouse’s position, i mean the entire character should rotate, but with how it currently works, the character faces the mouse’s position and not the gun, how can i fix this?
how i want it to look:
how it currently works:
the current script:
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
local Mouse = Player:GetMouse()
local Gun = nil
function StartRender()
TurnPlayer = RunService.RenderStepped:Connect(function()
local MousePosition = Vector3.new(
Mouse.Hit.Position.X,
HumanoidRP.Position.Y,
Mouse.Hit.Position.Z
)
local HRPPosition = HumanoidRP.Position
HumanoidRP.CFrame = CFrame.new(HRPPosition, MousePosition)
end)
end
Character.ChildAdded:Connect(function(Item)
if Item:HasTag("Gun") then
Gun = Item
StartRender()
end
end)
Character.ChildRemoved:Connect(function(Item)
if Item == Gun then
if TurnPlayer.Connected == true then
TurnPlayer:Disconnect()
end
Gun = nil
end
end)
it works at a distance but when the mouse gets close the character starts to go crazy
new script:
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
local Mouse = Player:GetMouse()
local Gun = nil
function StartRender()
TurnPlayer = RunService.RenderStepped:Connect(function()
local Offset = (Gun.Handle.Position - HumanoidRP.Position)
local MousePosition = Vector3.new(
Mouse.Hit.Position.X,
HumanoidRP.Position.Y,
Mouse.Hit.Position.Z
) - Vector3.new(Offset.X, 0, Offset.Z)
local HRPPosition = HumanoidRP.Position
HumanoidRP.CFrame = CFrame.new(HRPPosition, MousePosition)
end)
end
Character.ChildAdded:Connect(function(Item)
if Item:HasTag("Gun") then
Gun = Item
StartRender()
end
end)
Character.ChildRemoved:Connect(function(Item)
if Item == Gun then
if TurnPlayer.Connected == true then
TurnPlayer:Disconnect()
end
Gun = nil
end
end)
I tried your code in my studio (without the code to block the camera on top) And I didn’t shake like in your video.
I figured out a solution, you can disable character Rotation if the cursor is too close to you
Code:
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
local Mouse = Player:GetMouse()
local Gun = nil
function StartRender()
TurnPlayer = RunService.RenderStepped:Connect(function()
local Offset = (Gun.Handle.Position - HumanoidRP.Position)
local MousePosition = Vector3.new(
Mouse.Hit.Position.X,
HumanoidRP.Position.Y,
Mouse.Hit.Position.Z
) - Vector3.new(Offset.X, 0, Offset.Z)
local distance = (HumanoidRP.Position - MousePosition).Magnitude
local MaxDistance = 2
if distance > MaxDistance then
local HRPPosition = HumanoidRP.Position
HumanoidRP.CFrame = CFrame.new(HRPPosition, MousePosition)
else
-- Rotation stopped!
end
end)
end
well, it kind of works, but id prefer it to continue rotating the player at any distance, also when you say “without the code to block the camera on top”, if you meant without the camera being locked above the character looking down, i just tried it without it being locked and it still makes the player go crazy