Hello guys, i’m trying to make a House System with models that are already made, like in Adopt me.
But I’m having trouble centering the house models.
There is a centralized part in the middle of the map that serves as a reference, where the models should look. I’ve tried everything but nothing works
how do i make my models always look at a fixed position, do i need to set primaryparts or something?
to make a model always face a certain position, you can use the CFrame property of the model and the CFrame.lookAt method. The CFrame.lookAt method takes a position as an argument and returns a CFrame that points towards that position.
Here is an example of how you could use this method to make a model always face a certain position:
local model = game.Workspace.HouseModel
-- The position that the model should face
local targetPosition = Vector3.new(0, 0, 0)
-- Set the model's CFrame to a CFrame that points towards the target position
model.CFrame = CFrame.lookAt(model.Position, targetPosition)
This code sets the CFrame of the HouseModel object to a CFrame that points towards the targetPosition vector. This will make the model always face the targetPosition vector, regardless of where the model is moved.
You can modify this code to suit your needs, such as by using a different position as the target or by using a different object as the model.
local targetPosition = ...
local model = ...
local cf = model:GetBoundingBox()
local part = Instance.new('Part')
part.CFrame = cf
part.Parent = model
model.PrimaryPart = part
model:PivotTo(CFrame.lookAt(cf.Position,targetPosition))
part:Destroy()
It worked well but…
the model is facing directly in the direction of the part
how do I put only the exact direction?, like the model it’s really fixed to the ground
Fine, thank you!!
another question, here I see that it points exactly to the model, there is the possibility of putting the model pointing only to the exact direction, for example, as the house is on the left side of the model, instead of it pointing directly to the model, it just puts it in an exact direction understood in XYZ
example:
I don’t really get what you mean but you can use CFrame:ToOrientation()
local x,y,z = Part.CFrame:ToOrientation()
-- Part.CFrame is just an example
-- converting them into degrees because they are in radians
x = math.deg(x)
y = math.deg(y)
z = math.deg(z)
print(x,y,z)
think of exact directions within a cartesian plane (0,90,180,270)
I want the houses to be in this orientation only, and not their actual position in relation to the targetposition.