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

How can I Set the MaxTorque of a BodyGyro to a humanoids LookVector?

Asked by
BlagEz 26
5 years ago
Edited 5 years ago

I've been trying to set the MaxTorque of the BodyGyro to a humanoid LookVector for a while now but i can't seen to figure it out. This my whole script, thank you for helping me.

local UIS = game:GetService("UserInputService")
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
char = Player.Character
hum = char.Humanoid
root = char.HumanoidRootPart
local holdingUKey = false


UIS.InputBegan:Connect(function(inputObject) 
    if(inputObject.KeyCode==Enum.KeyCode.U)then
        holdingUKey = true
        while holdingUKey do
        local bp = Instance.new("BodyPosition")
        bp.Parent = char.UpperTorso
        bp.Position = char.UpperTorso.Position
        bp.P = 10000
        bp.D = 1250
        bp.MaxForce = Vector3.new(4000,4000,4000)
       local bg = Instance.new("BodyGyro")
     bg.Parent = UpperTorso
   bg.D = 500
bg.MaxTorque = Vector3.new(char.UpperTorso.Position,Mouse.hit.p)
bg.P = 9999999
bg.CFrame = CFrame.new(char.UpperTorso.Position, Mouse.Hit.p)
char.Humanoid.AutoRotate = false
            wait()
bg:Destroy()
bp:Destroy()
char.Humanoid.AutoRotate = true
        end

    end
end)
UIS.InputEnded:Connect(function(inputObject)
    if(inputObject.KeyCode==Enum.KeyCode.U)then
        holdingUKey = false
    end
end)
1
"They are redundant and its only use is in math." - this is not true. Please stop perpetuating this myth. fredfishy 833 — 5y
0
I still don't understand how i can fix my script. To work the proper way. BlagEz 26 — 5y
0
LookVector isn’t a property of humanoids. Second, and I could definitely be wrong, but I don’t think that is actually detecting that you’re holding the key down. It sees that input BEGAN, but not CONTINUED. Karasu_H 28 — 5y
0
Actually @Karasu_H, the variable 'holdingUKey' is set to true until the InputEnded event was fired. So it stays true until he lets go of the key he was holding. oilsauce 196 — 5y
0
It sounds like you want to set the CFrame of the BodyGyro and not the MaxTorque, which represents magnitude and not direction 1waffle1 2908 — 5y

1 answer

Log in to vote
0
Answered by 4 years ago

Judging by just the title, you want:

bg.MaxTorque = Vector3.new(LookVector.X, LookVector.Y, LookVector.Z)

Make sure you change the LookVector to the humanoid.LookVector

hope this helped?

Ad

Answer this question