How Do I Position A Part Orientation To 90 Degree For Z?

So I spawn a object in front of HumanoidRootPart, however, I want to change the rotation/orientation of the spawned object because it gets copied of the HumanoidRootPart. How can I achieve this?

kunai.CFrame = humanoidRootPart.CFrame
		
tweenService:Create(kunai, TweenInfo.new(1), {CFrame = kunai.CFrame + (humanoidRootPart.CFrame.LookVector * 150)}):Play()

This is the closest, but it only works on certain camera angle.

kunai.CFrame = CFrame.new(humanoidRootPart.CFrame.Position) * CFrame.Angles(0, 0, math.rad(90 - humanoidRootPart.CFrame.LookVector.Z))

Can anyone help me please, it be appreciated?

Try this


kunai.CFrame = humanoidRootPart.CFrame
		
tweenService:Create(kunai, TweenInfo.new(1), {CFrame = CFrame.new(kunai.CFrame + (humanoidRootPart.CFrame.LookVector * 150), CFrame.Angles(0,0,math.rad(90))}):Play()

Just create a new cframe with the 90 degree rotation

If you are looking to spawn the part without having the orientation of the HRP, then you could just do this.

local pos = humanoidRootPart.Position
kunai.CFrame = CFrame.new(pos)

This only takes in the position of the hrp and not the orientation.
I don’t know if that was what you were looking for, but this was a problem that I had trouble figuring out (even though it seems simple)

Could you explain what you’re looking for a little more?


To rotate a CFrame by 90 degrees around the z axis, just do:

local originalCFrame = ...
local rotatedAroundZ = originalCFrame * CFrame.Angles(0,0,math.rad(90))

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.