#How would i make a model look at a part
12 messages · Page 1 of 1 (latest)
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
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))
Appreciate it, but is it possible to achieve the same with :PivotTo as im pretty sure its newer and more modern?
If not thats fine but thank you either way
fair enough
Position isnt a propertie of a model
Cant you do Model:PivotTo(CFrame.lookAt(…)) or something? Also, you can get the model’s position with Model:GetPivot().Position (i think), assuming that was the problem
on phone so i was kinda unable tonsee the problem, sorry
i tried that it moves the model to some random obscure part of the workspace