How to ignore one axis on orientation

I’m working on a spell/magic tool that you can activate then it does some cool stuff creating blocks.
https://gyazo.com/48f7b6a675995d9db3fc57c2439ee731

I’m using the following code to create blocks in the direction the HumanoidRootPart is oriented.

local HumanoidRootPart = Character.HumanoidRootPart

for i=1, 15 do
	CreateNewBlock((HumanoidRootPart.CFrame * CFrame.new(7, 0, (-8 * i))).p)
	CreateNewBlock((HumanoidRootPart.CFrame * CFrame.new(-7, 0, (-8 * i))).p)
end

CreateNewBlock is a function which has a parameter for the target position, the CreateNewBlock function does the block instancing, material, etc.

The -8 * i is used to offset blocks from each other and -7 and 7 are used so both lines of blocks are offset from each other.

Now as you may see in the gif I linked above, the HumanoidRootPart was not only oriented on the Y axis, but also on the X and Z axis. This is a problem because you can see the line of blocks eventually going into the ground.

My question is, how do I ignore certain axis using my code and make the line of blocks go straight?

Instead of Root.CFrame, you can try this.

local Pos = Root.Position;
local X, Y, Z = Pos.X, Pos.Y, Pos.Z;
--// now, you can modify any of the above, as you like
--// for example, you can replace Pos.X and Pos.Z with 0 and they will be 0.

local NPos = Vector3.new(X, Y, Z);
local RootCFrame = CFrame.new(NPos);

--// Replace HumanoidRootPart.CFrame with RootCFrame
1 Like

Fixed it myself here using a perhaps more inefficient way.
Since I already had to raycast downwards to find the underneath part properties, I just raycast down for each block to find it’s Y axis, this will also help for non flat surfaces too.