Overview
I created a few lines that takes the mouse 3D position and calculates distance. I then divide the distance by the hexagon’s longest side (20 studs) and use a for loop to generate the required hexagons needed to get from the player’s torso to the mouse 3D position
Problem
When I cast the cframe onto the part using CFrame.new(pos,lookvector) I can’t get the hexagon to only rotate itself to the mouse’s position on the y rotational axis only. The code always rotates the hexagon on the z rotational axis which I don’t want. I want the hexagons to be flat and look at the mouse position on y rotational axis. How can I achieve this?
Code snippet
function makePath(plr,cf)
local char=plr.Character or plr.CharacterAdded:Wait()
local torso=char:WaitForChild('HumanoidRootPart')
local hex=game.ReplicatedStorage.Storage.Hexagon
local distance=math.abs((cf.Position-torso.Position).magnitude)
local partCount=math.floor(distance/hex.Size.X)
local interX=(cf.Position.X-torso.Position.X)/(hex.Size.X/2)
local interZ=(cf.Position.Z-torso.Position.Z)/(hex.Size.X/2)
for i=1,partCount do
local newhex=hex:Clone()
local pos=torso.Position+Vector3.new(interX*i,0,interZ*i)
pos=CFrame.new(pos,Vector3.new(0,cf.Position.Y,0))
newhex.CFrame=pos
newhex.Parent=workspace
end
end