Trying to make lookAt only look at x and z, does not work or give errors

I’m not sure how i’m supposed to do it, help is appreciated

local source = script.Parent
local targettolookat = game.Workspace.ScriptedArtillery.EndPointer

while wait() do
source.CFrame = CFrame.new(source.Position, Vector3.new(targettolookat.Position.x, source.Position.y, targettolookat.Position.z))
end```
1 Like

You can use the CFrame.lookAt() function
i think it can be used like this to fit your needs

source.CFrame = CFrame.lookAt(source.Position,Vector3.new(targettolookat.Position.X,source.Position.Y,targettolookat.Position.Z))
1 Like

It still isn’t rotating, could the thing I want to lookAt being a model be a cause?

1 Like
source.CFrame = CFrame.lookAt(source.Position,Vector3.new(targettolookat.WorldPivot.X,source.Position.Y,targettolookat.WorldPivot.Z))

in that case you need to use .WorldPivot instead of .Position

It’s still ot functioning, i dont think theres anything i can do

is source a model as well?
agaiapoegae character minimum

script.Parent is ScriptedArtillery

yes but what is scripted artillery? A model or a part?

scriptedartillery is the entire artillery cannon model including endpointer, its a model

Then source needs to use WorldPivot aswell

source.CFrame = CFrame.lookAt(source.WorldPivot,Vector3.new(targettolookat.WorldPivot.X,source.WorldPivot.Y,targettolookat.WorldPivot.Z))

this should work now

It’s not i think the issue is that endpointer is inside the scripted artillery, meaning that the model entire model can’t rotate to something that is inside it

inside as in sharing the same position value?

no, endpointer and the physical cannon are both inside scriptedartillery

so the position value is not the same? to confirm it, you should print pos of the start part and the end pos

1 Like

Here:

local source = script.Parent
local targetToLookAt = game.Workspace.ScriptedArtillery.EndPointer

while wait() do
    local sourcePosition = source.Position
    local targetPosition = targetToLookAt.Position

    local lookAtCFrame = CFrame.new(
        Vector3.new(sourcePosition.x, sourcePosition.y, sourcePosition.z),
        Vector3.new(targetPosition.x, sourcePosition.y, targetPosition.z)
    )

    source.CFrame = lookAtCFrame
end

This code calculates the lookAtCFrame by specifying the X and Z coordinates from the source and target positions, while maintaining the Y coordinate from the source position.

1 Like

What exactly is “EndPointer”? If it’s a Part. then EndPointer.Position is a world space position. If it’s an Attachment, then EndPointer.Position is relative to its Parent Part, and EndPointer.WorldPosition would be where it actually is in the world.

Obviously, in either case, if EndPointer gets moved when you change source.CFrame, then you have a positive feedback loop and the whole thing’s gonna chase its own tail.

1 Like

EndPointer is a part in his code due to its property name. Also what he is doing is looping forever as he use a while loop and not EndPointer:GetPropertyChangedSignal("Position) .

That doesn’t work and we know it. He should be using RunService or a loop that automatically stops when nobody is controlling the artillery.

yea I am explaining to him that the loop does not run when property change as it use while loop and not GetPropertyChangeSignal()

GetPropertyChangedSignal does not fire for certain properties like Position, much like how Changed behaves. At least this was the behavior I’ve observed years back.

Even if so, it does not have any performance benefit over RunService.