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

How to rotate a part relative to HumanoidRootPart with a script?

Asked by 5 years ago

when bullet is cloned it is facing the wrong direction, so it needs to be rotated 180. I tried putting a script in it changing it's orientation but that didn't work.

 local         bullet = game.ReplicatedStorage.Warrior.pull:Clone()
        bullet.Parent = game.Players.LocalPlayer.Character.Holder
        bullet.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame*CFrame.new(1, 0, -3)

2 answers

Log in to vote
1
Answered by
Audiimo 105
5 years ago
Edited 5 years ago

Try using CFrame.Angles().

(OtherPart).CFrame*CFrame.Angles(math.rad(x),math.rad(y),math.rad(z))

Doing math.rad() gets the numbers angle in radians making it easier to turn an object

0
How do I write that to rotate the part 180? Edbotikx 99 — 5y
0
Trying changing an X, Y, Z value until it fits your needs. the (X,Y,Z) need to be changed to a number. If you want them to do nothing make them 0 Audiimo 105 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

You could try to use CFrame:inverse() of the HumanoidRootPart and Motor6D added with a for loop to make the bullet propel along the x-axis. Links: https://wiki.roblox.com/index.php?title=API:Class/Motor6D http://wiki.roblox.com/index.php?title=CFrame#inverse

Most people would probably think to use SetPrimaryPartCFrame, but that isn't mean't to be used on something that is constantly moving, so the offset would gradually increase due to the script not being able to keep up with all the positions. This way the bullet will move along the x-axis depending on the center point which you would set as the humanoidrootpart.

Answer this question