local targetPo:Vector3 = mouse.Hit.Position
local targetCFrame = CFrame.lookAt(root.Position,targetPo) -- Same as CFrame.new with second parameter, but just makes easier to understand
-- || Changes ||
-- Now you just have to alter
targetCFrame *= CFrame.new(1,1,1)
on the subject of CFrames, I am making something point towards well, the mouse, but if its parent is rotated, the thing has a bit of offset and doesnt exactly point to the mouse, cause again, its parent is rotated, how can I fix that?
If I’m understanding correctly, couldn’t you just inverse whichever orientation the part0 has (assuming you’re trying to get part1 axis aligned)?
This gives me the following, the rotating part is Part0, the one that isn’t rotating is Part1:
I believe this is due to the order in which rotation is applied. Roblox’s “Orientation” is applied in YXZ order whereas CFrame.Angles is applied in XYZ order. Switch CFrame.Angles to CFrame.fromOrientation or equivalent, this should give you what you’re looking for
Ok works pretty well except only when facing forwards, as I am using math.min and math.max to limit the direction that the character can rotate, therefore messing it up when you face left or right, same with backwards:
So uh how can I go about fixing this one?
characterConnections['Heartbeat'] = RunService.Heartbeat:Connect(function()
-- // Point Character //
local targetPo:Vector3 = mouse.Hit.Position
local targetCFrame = CFrame.lookAt(root.Position,targetPo)
-- || Changes ||
local rx,ry,rz = targetCFrame.Rotation:ToOrientation()
local maxedX = math.max(math.min(math.deg(rx),25),-25)
--targetCFrame *= CFrame.Angles(maxedX,math.rad(0),math.rad(0))
local finishedCFrame = CFrame.new(0,0,0) * CFrame.Angles(math.rad(maxedX),ry,math.rad(0))
local test = CFrame.new(0,-0.5,0) * ViewmodelMotor.Part0.CFrame:Inverse().Rotation
ViewmodelMotor.C0 = test * finishedCFrame
end)
my guess is that I’d have to take finishedCFrame and rotate it by some other CFrame so idk
I see, I think what you’d want is to do is just use the targetCFrame for your orientation, then convert it to object space relative to the HumanoidRootPart’s CFrame. On the backend ToObjectSpace uses inverses but it’s easier to read. Also for R6 specifically, there is a C1 applied, we can remove that, and it should give you your intended result
local localPlayer = game:GetService('Players').LocalPlayer
local mouse = localPlayer:GetMouse()
local character = script.Parent
local torso = character:WaitForChild('Torso')
local rootPart = character:WaitForChild('HumanoidRootPart')
local root = rootPart:WaitForChild('RootJoint')
local MAX_ROTATION = math.rad(25)
game:GetService('RunService').Heartbeat:Connect(function()
local mouseHit = mouse.Hit
local targetCFrame = CFrame.lookAt(rootPart.Position, mouseHit.Position)
local cframeRelative = rootPart.CFrame:ToObjectSpace(targetCFrame)
local rX, rY, rZ = cframeRelative:ToOrientation()
rX = math.clamp(rX, -MAX_ROTATION, MAX_ROTATION)
root.C0 = CFrame.fromOrientation(rX, rY, 0) -- since c0 is part1 relative to part0
root.C1 = CFrame.identity
end)