Hello! (I know this question has been asked before, but the provided solutions just don’t work in my situation.)
I’m working on a third person shooting system and have now begun working on making it so that the players torso actually follows the mouse so you don’t have that situation where you’re shooting down but your character is facing dead straight ahead.
I want the system to be similar to SCP: Roleplay’s third person shooting system.
Which can be seen here:
https://www.youtube.com/watch?v=trj9mGAAP-Y
I’ve tried the solution to this question: Need help with torso and head following mouse
Which almost gets me there but the torso only slightly rotates up and down, but I want it to be able to rotate to look at the ceiling and rotate to look all the way at the floor.
As stated I’m using the script from the linked attempted solution which is.
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local PlayerMouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Neck = Head:WaitForChild("Neck")
local Torso = Character:WaitForChild("UpperTorso")
local Waist = Torso:WaitForChild("Waist")
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local NeckOriginC0 = Neck.C0
local WaistOriginC0 = Waist.C0
Neck.MaxVelocity = 1/3
RunService.RenderStepped:Connect(function()
local CameraCFrame = Camera.CoordinateFrame
if Character:FindFirstChild("UpperTorso") and Character:FindFirstChild("Head") then
local TorsoLookVector = Torso.CFrame.lookVector
local HeadPosition = Head.CFrame.p
if Neck and Waist then
if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then
local Point = PlayerMouse.Hit.p
local Distance = (Head.CFrame.p - Point).magnitude
local Difference = Head.CFrame.Y - Point.Y
Neck.C0 = Neck.C0:lerp(NeckOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 1, 0), 0.5 / 2)
Waist.C0 = Waist.C0:lerp(WaistOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 0.5, 0), 0.5 / 2)
end
end
end
end)
I know this is probably a relatively easy fix, but I’m horrible at CFrame and Math in general so I try to stay away from it. Because of these two factors I’ve just put off actually properly learning CFrame which I know I should.
Thanks In Advance.