I’m spawning vehicles, and I want them to look specifically towards the spawner. There will be multiple orientations these spawners are placed at, so I need a way to calculate the orientation I want the model to be at. Here’s my current code, but it doesn’t really rotate the part and just moves it. I’m not very good with CFrames, if someone who is could explain this a little more that would help.
To make a “part’s position” look at another position that can be simply defined as CFrame.new(Position, LookAtPosition). So that means that using your code above:
This worked for me, but one more question. The part I was trying to spawn is engulfing the whole spawner and everything. How would I make sure to keep it on or behind the spawn pad?
Yes, I’ve used GetBoundingBox to make a box the entire size of the model. This represents what would happen if a Model was spawned in because the actual model would fling out of the map before I can see it. Here’s my testing code.
local Plane = script["F-15"]
local Spawn = workspace["Spawn"]
local Orientation, Size = Plane:GetBoundingBox()
local CurrentPosition = Plane.PrimaryPart.Position
local Part = Instance.new("Part", workspace)
Part.Anchored = true
Part.CanCollide = false
Part.Size = Size
Part.CFrame = CFrame.new(
Vector3.new(
Spawn.Position.X,
Spawn.Position.Y + (Size.Y / 2),
Spawn.Position.Z
)
, Vector3.new(Spawn.Spawn.Position.X, Spawn.Position.Y + (Size.Y / 2), Spawn.Spawn.Position.Z))
Part.Name = "Oof"
Alright, and so what exactly is the problem? When you say engulfing, do you mean it’s not spawning correctly and it’s partly spawning in the ground? or…?
When a model gets it’s CFrame set, it sets it relative to the center. If you want it to spawn behind it, you’ll need to move the model in the X or Z axis by half the size (like you did on the y)
I’m working on it. It’s a plane and they rotate, so I have to set the CFrame again after it loads and does a 90 degree rotation or set a 90 degree rotation so it can just rotate into its position.