How do I make a model look at a certain point

Hi, so I have a Turret that’s mounted to the ceiling. There’s two models inside it with two primary parts, one being the Turret’s Left and Right rotation, and the second being the Turret’s Up and Down rotation. What I’m trying to do is whenever a player gets too close, the turret will detect the player and shoot at them (which I’ve already done). Here’s one of my previous attempts:

--// Change Position of the turret
			local ray1 = Ray.new(Turret.PrimaryPart.Position + Vector3.new(Turret.PrimaryPart.Size/2,0,0), Turret.PrimaryPart.CFrame.LookVector)
			local ray2 = Ray.new(Laser.PrimaryPart.Position + Vector3.new(Laser.PrimaryPart.Size/2,0,0), Laser.PrimaryPart.CFrame.LookVector)
			
			Turret:SetPrimaryPartCFrame(CFrame.new(Turret.PrimaryPart.Position.X,Turret.PrimaryPart.Position.Y,Turret.PrimaryPart.Position.Z) * CFrame.Angles(ray1.Direction.X, ray1.Direction.Y, math.rad(-90)))
			Laser:SetPrimaryPartCFrame(CFrame.new(Laser.PrimaryPart.Position.X,Laser.PrimaryPart.Position.Y,Laser.PrimaryPart.Position.Z) * CFrame.Angles(ray2.Direction.X,ray2.Direction.Y,ray2.Direction.Z))

The result of the above makes the turret flip to the completely wrong direction. How would I go about fixing this?

1 Like

This question has been asked before. I believe this post should answer your question.

1 Like

I believe this is exactly what you’re looking for: https://youtu.be/CPcaJgQkxM8

Hope this helps!