So I’m trying to change the part orientation based on player facing, and it doesn’t seem to work.
Let say I’m facing this way:
This is what the hitbox creates:
local hb = Instance.new("Part", fx)
hb.Name = "HB"
hb.Size = Vector3.new(12, 14, 45)
local pos = humanoidRootPart.Position
hb.CFrame = CFrame.new(pos) * CFrame.Angles(0, humanoidRootPart.CFrame.LookVector.Y, 0)
hb.Anchored = true
hb.CanCollide = false
hb.Material = Enum.Material.ForceField
hb.Transparency = 0.5
This below works; however, I want to slightly change the position of the CFrame.
hb.CFrame = humanoidRootPart.CFrame
Wouldn’t it be easier to just set the hitbox’s orientation to the player’s RootPart orientation?
If you just set the hitbox cframe to be the humanoid root parts cframe it matches rotation and position
Ok, but just copy the hitbox’s current position and replace the rotation with the humanoid root part’s rotation?
1 Like
As @TestyLike3 said, you could just set the position of the hitbox to be the player’s root position and then edit the orientation to be the hitbox’s position. This is simpler than using CFrames and increases readability of your code.
I want to change the position and the orientation. That why I’m doing it this way.
But why do that in desperate steps when you can do it in 1 line? With 5 words
Yes but the concept of cframe is that it stores rotation and positional values. So using it is a better practice
If you want it to stick to the character your going to need to add something called a weld constraint
I’m not trying to stick to my character, it a hitbox. All I need is the hitbox to be facing the right direction when created then it gets deleted.
What rotation are you referring about? Orientation is the rotation?
local hb = Instance.new("Part", fx)
hb.Name = "HB"
hb.Size = Vector3.new(12, 14, 45)
local pos = humanoidRootPart.Position
hb.CFrame = CFrame.new(pos) * humanoidRootPart.CFrame.Rotation
hb.Anchored = true
hb.CanCollide = false
hb.Material = Enum.Material.ForceField
hb.Transparency = 0.5
CFrame.Rotation is a copy of the CFrame but with no position, only rotation.
Also, wouldn’t you make a loop on that? Or it’s just for one time?
It’s one time, I honestly didn’t know CFrame rotation is a thing. I’ll try it, thanks.
That can also be written as
local hb = Instance.new("Part", fx)
hb.Name = "HB"
hb.Size = Vector3.new(12, 14, 45)
hb.CFrame = humanoidRootPart.CFrame
hb.Anchored = true
hb.CanCollide = false
hb.Material = Enum.Material.ForceField
hb.Transparency = 0.5
system
(system)
Closed
August 21, 2024, 4:30pm
#15
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.