I've been working with making a custom combat system, and have had some issues with getting the weapons to point correctly.
I've tried making the physical tool a model (other than handle) and setting a primary part, then setting its CFrame to the calculated distance from the character, yet to no avail.
I'm not asking this to be made for me of course, I'd just love to know how I could generally accomplish coding this.
Thank you for reading, and I hope to find a solution!
EDIT: Current code:
mouse.Move:connect(function() if mouse.Hit then script.Parent.spear:SetPrimaryPartCFrame(CFrame.new(script.Parent.spear:GetPrimaryPartCFrame().p, mouse.Hit.p)) end end)
(mouse is defined earlier in the script)
To do this, I recommend setting the CFrame of the PrimaryPart. There are two important methods of Model objects while doing this: SetPrimaryPartCFrame
and GetPrimaryPartCFrame
.
When you set the PrimaryPart's CFrame via SetPrimaryPartCFrame
, every other part in the model gets it's CFrame changed relative to the PrimaryPart. To make it look at a point you can use the constructor CFrame.new(Vector3 position, Vector3 point).
local model = game.Workspace.Model local mouse = game.Players.LocalPlayer:GetMouse() mouse.Move:connect(function() if mouse.Hit then model:SetPrimaryPartCFrame(CFrame.new(model:GetPrimaryPartCFrame().p, mouse.Hit.p)) end end)