You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
-
What is the issue? Include screenshots / videos if possible!
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--- Services ---
local Players = game:GetService("Players");
local RunService = game:GetService("RunService");
local Workspace = game:GetService("Workspace");
wait();
--- Declarations ---
local Player = Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();
local Camera = Workspace.CurrentCamera;
--- Character ---
local RightUpperArm = Character:WaitForChild("RightUpperArm");
local RightShoulder = RightUpperArm:WaitForChild("RightShoulder");
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart");
local EE = Character:WaitForChild("UpperTorso");
local Waist = EE:WaitForChild("Waist");
local Head = Character:WaitForChild("Head");
local Neck = Head:WaitForChild("Neck");
local camLimit = RunService.Stepped:Connect(function()
local CameraCFrame = HumanoidRootPart.CFrame:ToObjectSpace(Camera.CFrame)
local x, y, z = CameraCFrame:ToOrientation()
local a = Camera.CFrame.Position.X
local b = Camera.CFrame.Position.Y
local c = Camera.CFrame.Position.Z
local xlimit = math.rad(math.clamp(math.deg(x),-75,75))
local ylimit = math.rad(math.clamp(math.deg(y),-75,75))
local zlimit = math.rad(math.clamp(math.deg(z),-75,75))
Camera.CFrame = HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(a,b,c) * CFrame.fromOrientation(xlimit,ylimit,zlimit))
end)
--- Execution ---
RunService.Stepped:Connect(function()
local cameraCFrame = Camera.CFrame;
-- Get the direction by taking the forward vector of the camera
local direction = cameraCFrame.LookVector * 5000;
-- Get the rotation offset
local rootCFrame = HumanoidRootPart.CFrame;
local rotationOffset = (rootCFrame - rootCFrame.Position):Inverse();
-- Calculate the new transforms
RightShoulder.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), direction) * CFrame.Angles(math.pi / 2, 0, 0);
Waist.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), direction) * CFrame.Angles(math.pi / 20, 0, 0);
Neck.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), direction) * CFrame.Angles(math.pi / 25, 0, 0);
end)
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = HumanoidRootPart
bodyGyro.MaxTorque = Vector3.new(0, 4000, 0)
local delay = 0.36
while true do
wait()
wait(delay)
local targetPosition = HumanoidRootPart.Position + Vector3.new(Camera.CFrame.LookVector.X, 0, Camera.CFrame.LookVector.Z)
local targetCFrame = CFrame.new(HumanoidRootPart.Position, targetPosition)
local alpha = 0.05
HumanoidRootPart.CFrame = HumanoidRootPart.CFrame:lerp(targetCFrame, alpha)
-- Adjust character orientation using BodyGyro
local lookDirection = (targetPosition - HumanoidRootPart.Position).unit
bodyGyro.CFrame = CFrame.new(HumanoidRootPart.Position, HumanoidRootPart.Position + lookDirection)
end
Please do not ask people to write entire scripts or design entire systems for you. If you can't answer the three questions above, you should probably pick a different category.