Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make an entire welded model face the Player's mouse direction?

Asked by 8 years ago

So I am trying to create a robot/mech where instead of using the A and D keys to turn, the model turns to where the mouse points. I have this script that works when I test it on the head-to-torso weld (I have the welds set up like a character) but when I run the script for the Torso to HumanoidRootPart weld it doesn't function. I think this is due to the fact that the Torso is the C0 for the other limb welds...

Mouse.Move:connect(function()
    if Tool.Active == true then
    local Hit = Mouse.Hit
    Vehicle.HumanoidRootPart.Root.C1 = (CFrame.new(Vehicle.Torso.Position, Mouse.Hit.p)):toObjectSpace(Vehicle.HumanoidRootPart.CFrame * Vehicle.HumanoidRootPart.Root.C0)
    end
end)

Like I said, it all runs properly if I run it on a weld where the C1 object doesn't have any other welds, but when it does have other welds it doesn't work. Is there another way I should be doing this? Is there a more efficient way of making a model face the mouse, a way that works?

Answer this question