St1zz
(St1zz)
July 14, 2020, 6:39pm
#1
I attached a Body Gyro to my characters HumanoidRootPart to make them face the direction their mouse is pointing. But I only want them to face the X and Z Axis and leave the Y Axis the same.
Script:
local ATKGyro = Instance.new("BodyGyro")
ATKGyro.Parent = char.HumanoidRootPart
ATKGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
ATKGyro.D = 100
ATKGyro.P = 10000
ATKGyro.CFrame = Mouse.Hit
Video:
blokav
(blokav)
July 14, 2020, 6:43pm
#2
For the MaxTorque try this:
ATKGyro.MaxTorque = Vector3.new(math.huge, 0, math.huge)
Alternatively you can adjust the CFrame to stay in the XZ plane before setting it to the BodyGyro’s CFrame.
St1zz
(St1zz)
July 14, 2020, 6:52pm
#3
I tried this and it doesnt seem to do anything. Heres a video of what happens:
(When I attack, it doesnt face the direction im aiming)
Cerulean7
(Cerulean7)
July 14, 2020, 7:12pm
#4
try replacing this
ATKGyro.CFrame = Mouse.Hit
with this:
ATKGyro.CFrame = CFrame.new(Mouse.Hit.Position * Vector3.new(1, 0, 1))
Multiplying it by Vector3.new(1, 0, 1)
removes the Y component by making it 0 and keeps the X and Z components the same. (then you have to turn it back into a CFrame using CFrame.new()
)
0pSt_ts
(0pSt_ts)
July 14, 2020, 7:18pm
#5
You have to put a loop around where you set the CFrame.
blokav
(blokav)
July 14, 2020, 7:30pm
#6
When you construct a CFrame using the single Vector3 argument it’s orientation defaults to 0, 0, 0.
ATKGyro.CFrame = CFrame.new(Vector3.new(0, 0, 0), Mouse.Hit.LookVector * Vector3.new(1, 0, 1))
Since position doesn’t matter for bodygyros, they can just use the LookVector
1 Like