How do I make a model point towards a position?

I looked around a bit and could not figure it out.
How would I make a model point towards a position?

You could use CFrame.lookAt() using the model’s PrimaryPart.

So like.

model.PrimaryPart.CFrame.lookAt(position)

?

model.PrimaryPart.CFrame = CFrame.lookAt(position, position)

You would use CFrame.lookAt(model.PrimaryPart.Position, position)

position would be the position you want it to look at.


Just like @msix29 did.

I tried this.
Its only rotating the primaryPart and not the other parts in the model.

Try welding all of the parts in the model to the PrimaryPart using WeldAttachments

You need to weld everything for this to work.

you can use the CFrame object and the CFrame.lookAt function. Here’s a simple script to make a model point toward a target position:

-- Define the model and target position
local model = workspace.Model -- Replace with your model's name or reference
local targetPosition = Vector3.new(0, 0, 0) -- Replace with the desired target position

-- Function to make the model point towards the target position
function pointModelTowardsPosition(model, targetPosition)
    local modelPrimaryPart = model.PrimaryPart
    if not modelPrimaryPart then
        print("Model does not have a PrimaryPart set")
        return
    end

    local modelPosition = modelPrimaryPart.Position
    local lookAtCFrame = CFrame.lookAt(modelPosition, targetPosition)

    -- Update the model's PrimaryPart CFrame
    model:SetPrimaryPartCFrame(lookAtCFrame)
end

-- Call the function to make the model point towards the target position
pointModelTowardsPosition(model, targetPosition)
1 Like

Just a question involving the welding.

Should I make the Part0 the PrimaryPart or the other parts?

All part0 should be the primaryPart and Part1 should be the part connecting to it (every other part, one by one).

1 Like

You can run a simple for loop in the command bar to do this for you btw

local model = workspace.Model for i, v in pairs(model:GetChildren()) do if v ~= model.PrimaryPart then local a = Instance.new("WeldConstraint") a.Parent = model.PrimaryPart a.Part0 = model.PrimaryPart a.Part1 = v a.Name = v end end

Well thanks yes this works!
Im pretty sure you said this first so thanks!

1 Like

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