Contents
- Preface
- Primer on Pivots
-
Placement Examples
3.1. Quick Prop Placement
3.2. SCP Facilities (“Repeat Hallway Simulator” Style)
3.3. RPG Dungeon Rooms - Rigging and Placing Models
Preface
Some builders may already be deeply acquainted with the style I’m going to showcase. To save you time: this tutorial is all about assembling large sets together like LEGOs.
Pivots are a recent addition to the API which are extremely useful to development. Pivots allow you to modify the point at which you commit rotations and translations around. They are viable for both individual parts and entire models with or without a PrimaryPart.
…what if I told you that they were equally as viable for builders to control movement with as they are for placing prefabs easily as a programmer? I might be stating the obvious here, but I feel it’s so awesome to be able to use pivots in my workflows as a programmer too.
Today, I’d like to share a tutorial on how you can use code to generate layouts or place assets very quickly. This is not just for programmers though; builders can also pick this up to help expedite their building (not a substitute for plugins that can do this better, though!).
Whether you’re just making some simple props that you want to repeat quickly, building SCP facilities that are big on hallways or even fitting rooms for a caverns map in an RPG experience to give some uniqueness to each run, pivots may just be your time-saving friend!
Primer on Pivots
As mentioned in the preface, pivots are a new member to the API which help you control the points at which you commit rotations and translations around. Pivots are displayed in the viewport as a blue-outlined white dot, as shown below:
In addition to being able to define where you want to commit rotations and translations around, you can also summon the handles directly to your cursor by holding Tab.
Along with pivots come a selection of properties and scriptable APIs so you can manipulate pivots as well as the coordinates of objects based on their pivots. The latter is what we’re going to be focusing on; using the scripting APIs to place assets.
Placement Examples
To bring this tutorial home a bit more and intrigue you with the content to come, I thought about starting off with some examples of the placements you can perform with pivots. I’ll keep this real with some use cases I’ve observed from developers through various categories and help requests.
I’ll keep each really brief so I don’t take up too much of your time. The main takeaway is that we’re essentially assembling things together like LEGOs.
Quick Prop Placement
(Public assets by LonuxWolf; Archimedes Two by Scriptos)
Turn a couple of markings and a prop prefab:
Into (what would be) a decorated area:
SCP/SciFi Facilities ("Repeat Hallway Simulator" Style)
(Building by TheRealSuperNova for a project of ours)
Turn a hallway prefab and some reference points organised in a layout:
Into a fully structured long hallway:
RPG Dungeon Rooms
(Building by WindScourge for a project of ours)
A caverns map with spaces for room generation:
Into a filled map with rooms attached to the terrain:
Rigging and Placing Models
Let’s get right into it, starting with how to rig. Truly, doing all of this is extremely easy so I’m in essence just presenting a new way of fast building repetitive content.
Simply, all you need is a reference point that you can use as the PrimaryPart for your models. Models do not require PrimaryParts to work with pivots so if you’re good at visualising or placement then you can even do this by hand. PrimaryParts help with visualisation, alignment and spatial awareness when setting up your layout at first.
Your PrimaryPart can be literally anything, even just the bottom space of your model. To revisit LonuxWolf’s plant stand model, I’ve opted to create a red brick at the bottom. I then clone that and place it around wherever I want more plant stands. This tells me that I should reserve a certain amount of space because a plant stand model will be placed there.
Now I take that red brick and distribute it wherever I want. Revisiting my prop placement example, I just took out Archimedes Two and made an incomplete circle of these red bricks. This means “these spaces are where I want my plant stands”.
And now the final part is to clone the plant stand and pivot it to these red bricks!
-- Let's create a folder of new plant stands. If we decide we don't like
-- the placement, we can delete the folder and run the code again.
local newPlantStandsFolder = Instance.new("Folder")
newPlantStandsFolder.Name = "NewPlantStands"
newPlantStandsFolder.Parent = workspace
-- Loop through all the markers we placed.
for _, marker in ipairs(workspace.PlantStandMarkers:GetChildren()) do
-- Clone the plant stand prefab so we have a new model.
local plantStand = workspace.PlantStand:Clone()
-- Pivot the new plant stand to the marker's pivot. We're essentially
-- snapping the two pivot points together.
plantStand:PivotTo(marker:GetPivot())
-- Remove the plant stand bases. This way, if we're satisfied
-- with the plant stand positions, we can delete the markers
-- and be left with no red box artifacts.
plantStand.PrimaryPart:Destroy()
plantStand.PrimaryPart = nil
-- Parent the plant stand to the new folder
plantStand.Parent = newPlantStandsFolder
end
Just like that, you’re done! This may be just plant stands decorations, but you can take it even further with the placement examples above and generate entire buildings. You could do floor generation for Tower of Hell or Zombie Tower experiences too, or even use this same paradigm for plot building experiences. The possibilities are truly endless and fun too!
Postface
I hope this primer has been informational to you as a developer on a use case for pivots. Placement of prefabs en masse or trying to create layouts with prefabs is definitely something I see many developers trying to do now but potentially may have not known of this “LEGO-building” method. It is made so much easier with pivots and anyone can jump on board fast!
It’s been a long while since I’ve written a tutorial. Please do let me know if you have any feedback or suggestions! Perhaps some things you liked or thought could be improved (I tend to be pretty verbose even for simple topics like this that can be explained in a paragraph or less ) or some help questions you’ve stumbled across while attempting this. As always, keep it constructive.
Happy developing!