Need help with LookVector and some math

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    image
    trying to get it to work with the humanoidrootpart lookvector

  2. What is the issue? I can’t get the code to work with LookVector, it might have something to do with the count and split variable. Heres what theyre for
    image

Here’s what I have rn

local count = 0
local split = -7
local size = 4

mouse.Button2Down:Connect(function()
    local bpx = hrp.Position.X
    local bpz = hrp.Position.Z
    local hcf = hrp.CFrame.LookVector
    
    count = 0
    split = -7
    size = 4
    
    for i = 1,15 do
        wait()
        count += 3
        split += 0.3
        size -= 0.1

        local p1 = part1:Clone()
        local p2 = part2:Clone()

        p1.Parent = workspace.Effects
        p2.Parent = workspace.Effects
        
        p1.Position = Vector3.new(bpx+count,10,bpz-split)
        p2.Position = Vector3.new(bpx+count,10,bpz+split)

if there are any better way to do it, please tell me, i would appreciate it :smiley:
might be some minor issues, i just cant figure it out, thank you

What exactly are you trying to do? You want p1 and p2 to be relative to the direction the character is looking?

yeah I think so, with lookvector, so mess with the CFrame

pretty sure its heavily got to do with the count variable, where if its plus it will go frontward, if the count is min, it will go backward as mentioned earlier, i have no experience with this kind of things
the split variable might be causing issues too for the script. I’m trying to look for a way to do this, if there are any forums dedicated to this, pwease shawe :pleading_face:

So with CFrames the documentation is great! I can roughly explain what I think you need.

local Offset = CFrame.new(1,0,-5)

Part.CFrame = Part.CFrame * Offset
-- this will move the part 1 stud to the side, 0 studs up, and 5 studs forward from its original CFrame!  So a part that's "looking down" will move down 5 studs.

Part.CFrame = Part.CFrame + Vector3.new(0,10,0) -- this will move the part up 10, no matter what the original CFrame is! So no matter what way its looking it will always move up.

Setting a parts CFrame is a much more accurate way to move parts usually!

I think most of what you’re looking for would be

p1.CFrame = CharacterRootPart.CFrame * CFrame.new(bpx+count,10,bpz-split)

figured it out! thanks for the help.

edit. I’m doing it another way

You cannot change lookVector itself, because it’s read-only. But you can do some math to get the direction of other faces. lookVector is the direction of the Part’s FrontFace, so using this we can get the other faces pretty simply;

--Forward
part.CFrame.lookVector

--Backward
-part.CFrame.lookVector

--Left
(part.CFrame * CFrame.Angles(0, math.rad(90), 0)).lookVector

--Right
-(part.CFrame * CFrame.Angles(0, math.rad(90), 0)).lookVector

If you found my answer helpful, be sure to mark it as the solution! :white_check_mark: