#How would i make a model look at a part

12 messages · Page 1 of 1 (latest)

zinc solar
#

im trying to achieve what would normally done by cframe.lookat, except im working with models

#

How would i make a model look at a part

#
function Presets.RuinedSolarStation(Parent)
    local ClonedStation = RuinedSolarStation:Clone()
    local ClonedStationPrimary = ClonedStation:FindFirstChild("Primary")
    ClonedStation.Parent = Parent    
    
    -- Generation
    local CLONED_STATION_POSITION = CFrame.new(Parent.Position.X + math.random(750, 1000), Parent.Position.Y + math.random(750, 1000), Parent.Position.Z + math.random(750, 1000))
    
    ClonedStation:PivotTo(CLONED_STATION_POSITION)
end

This is the script im working with, clonedstation is a clone of a model with a primary part. Positioning it works fine when i use :PivotTo but i wouldnt know how to rotate it instead of positioning it

light badge
#
local model = game.Workspace:WaitForChild("Model")
local part = game.Workspace:WaitForChild("Part")

-- Calculate the vector from the model to the part
local vector = part.Position - model.Position

-- Rotate the model so that its Z axis is pointing towards the vector
model:SetPrimaryPartCFrame(CFrame.new(model.Position) * CFrame.LookAt(Vector3.new(), vector))
zinc solar
light badge
#

i don't really care what way it's done

#

as long as it works

zinc solar
zinc solar
wicked mortar
#

on phone so i was kinda unable tonsee the problem, sorry

zinc solar