How to ignore Y axis on CFrame.lookAt(at, lookAt)

Trying to make a gaster blast that looks at the mouse, but if the mouse looks up at the sky make it just face the direction excluding the y axis…

if Char:FindFirstChild("Gaster Blaster") and Gaster then 
			if sf.SetCooldown({plr = player, ability = "Gaster1", check = true}) then return end
			sf.SetCooldown({plr = player, ability = "Gaster1", dura = 2})
			
			local gasterCopy = repStorage.Rigs["Gaster Blaster"]:Clone()
			gasterCopy.PrimaryPart.Position = (Root.CFrame * CFrame.new(Random.new():NextNumber(-20, 20), 2,0)).Position
			gasterCopy.PrimaryPart.CFrame = CFrame.lookAt(gasterCopy.PrimaryPart.Position, Vector3.new(mouseHit.Position.X, 0, mouseHit.Position.Z))
			gasterCopy.Parent = workspace.Effects
			
			for Index, BodyParts in ipairs(gasterCopy:GetChildren()) do
				if BodyParts:IsA("BasePart") and BodyParts.Name ~= "HumanoidRootPart" then
					TweenModule.obj(BodyParts, "Quad", "InOut", .4, {Transparency = 0})
				end
			end
1 Like

Not sure what you mean. Do you want to include it or ignore it?

local look = CFrame.lookAt(part.Position, other.Position)
local x, _, z = look:ToOrientation()
return CFrame.new(look.Position) * CFrame.Angles(x,0,z)

Something like this may work. If it is angled improperly, try switching out CFrame.Angles for other methods which apply rotations in a different order.

1 Like

You can also do this:

local from, to = Vector3.new(Pretend), Vector3.new(Pretend)
local direction = (to - from) * Vector3.new(1, 0, 1)
local cframe = CFrame.lookAt(Vector3.zero, direction) + from

You can also do this with CFrame.fromMatrix and have a customized up vector.

1 Like

I just did,
at.CFrame = CFrame.lookAt(at, vector3.new(lookAt.X, at.Y, lookAt.Z))

1 Like

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