# Pivot and LookingAt

Hello! I want the cylinder to always face the red cube. How could I do that?

When I do it, the cylinder goes crazy (the image is for reference, but in the real cylinder I have the pivot at the top of the cylinder so that it does not move from a base that supports it)

2 Likes

It sounds like youâ€™re trying to make a turret that points at something. Have you searched for solutions before posting?

At first I tried something like this:

``````Cube.Position = Vector3.new(-62.5, 2.875, 17)
Cube.Position = Vector3.new(Cube.Position.X + rx, Cube.Position.Y, Cube.Position.Z + rz)
Cylinder.CFrame = CFrame.lookAt(Cylinder.Position, Cube.Position)
``````

But apparently the pivot has some influence

I am trying to aim at the face without modifying the position of the object

``````Cylinder.CFrame = CFrame.new(Vector3.new(Cube.Position.X + rx, Cube.Position.Y, Cube.Position.Z + rz)) * CFrame.lookAt(Cylinder.Position, Cube.Position)
``````

this should help!! ************

uhh rx and ez are not definedâ€¦

``````local rs = game:GetService("RunService")
local xOffset, yOffset, zOffset = 0, 0, 0
local cyl = ...

rs.RenderStepped:Connect(function(dt)
cyl.CFrame = CFrame.lookAt(cyl.Position, Cube.Position + Vector3.new(xOffset, yOffset, ZOffset)
end)
``````

mess with the offset values; if its looking too high up, reduce `yOffset`, etc.

Itâ€™s more easier than you think, really.

``````local partA = workspace.PartA --The part that looks
local partB = workspace.PartB --That part that will be looked at

Iâ€™d only use RunServiceâ€™s `Heartbeat` if the code you run per frame isnâ€™t that big, since it can severely use up memory and performance if so.