Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

2 comments

0

How do I write that to rotate the part 180?

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.