I’ve never been that well with CFrames and need a little help.
I’m trying to make the player’s right arm point toward the mouse, but when the character turns around 180 degrees, it appears to function as if the character wasn’t rotated 180 degrees.
IT’s something to do with world and object space, but I’m unsure of how to resolve this issue.
https://gyazo.com/c5f415b3749bc818470008d6c4aed119
When the player rotates is the problem, as it is pointing behind not in front. It’s not taking the current rotation of the character into consideration. How can I make it work for all rotations of my character?
Current code:
local Players = game:GetService(“Players”)
local plr = Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local armOffset = char.UpperTorso.CFrame:Inverse() * char.RightUpperArm.CFrame
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local char = Player.Character or Player.CharacterAdded:Wait()
local Root = char:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")
local CN,CA = CFrame.new,CFrame.Angles
local an = math.asin
local armOffset = char.Torso.CFrame:Inverse() * char["Right Arm"].CFrame
local armWeld = Instance.new("Weld")
armWeld.Part0 = char.Torso
armWeld.Part1 = char["Right Arm"]
armWeld.Parent = char
RunService.Heartbeat:Connect(function()
local cframe = CN(char.Torso.Position, Mouse.Hit.Position) * CA(math.pi/2, 0, 0)
armWeld.C0 = armOffset * char.Torso.CFrame:toObjectSpace(cframe) * CN(0,0,-0.5)
end)
Using tweenservice, you can tween your arm to the “mouse position” while being constantly updated via remoteEvent and you can use magnitude so that way it doesn’t always render or run for other players while out of a certain distance.
Also, if you don’t mind, after getting the server replication fixed, I have a problem with the arm pointing, it kind of bugs when aiming at the ground (while using shift lock), I might make a post when I get the chance to record it