Hello! I am trying to make a system simmilar to the head to camera direction movement, but I really do suck at math.
Basically, I am trying to point the right hand, when a tool is held, towards the direction of where the camera is looking, but only on the y axis. I want to achieve this because I am making a flashlight system, and I want to keep it realistic.
I also want so both the server and the client see it and for it to use R6.
I have found some media of what I’m trying to achieve (the head movement isn’t needed): External Media
If you have any questions let me know.
If you don’t want to download the file, I found an alternative:
I haven’t tested it but i hope this will give you an idea on how to do it.
You can put this code in a LocalScript in StartPlayerScripts for example.
local Players = game:GetService('Players)
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer:WaitForChild(“Character”)
while true do
local PlayerArm = Character.RightArm
local LookDirection = game.Workspace.CurrentCamera.CFrame.LookVector
local CosAngle = Vector3.new(0, 1, 0):Dot(LookDirection)
local Angle = math.acos(CosAngle)
local AngleInDegres = (Angle / math.pi) * 360
PlayerArm.CFrame = PlayerArm.CFrame * CFrame.Angle(0, AngleInDegres, 0)
The goal is to take the angle between a default vector, here (0, 1, 0) and the lookVector of your camera.
Then you have to rotate your arm with that angle using CFrame.
Sadly, it just bugs out the whole character until I fall into the void.
It’s because he’s trying to set the CFrame instead of a weld C0.