Hey Creators,
We’re thrilled to introduce the latest addition to Roblox Studio: the WorldRoot:StepPhysics
API. This powerful new plugin-level API is part of our ongoing efforts to improve the usability of the Roblox Physics Engine and is designed to make creating physics-based systems easier and faster.
What is WorldRoot:StepPhysics
?
The StepPhysics
function enables you to advance the world, or part of it, forward by a specified amount of time. This functionality is available on both the Workspace and WorldModels. The API accepts two arguments: a timestep and an optional set of parts. The physics solver in Roblox will then simulate the specified parts, moving them accordingly.
Please keep in mind that this API has Plugin Security, meaning you won’t be able to use it in published experiences.
Key Features:
- Single Step Simulation: Advance your world by a single step with precise control over the timestep and the parts to simulate.
-
Flexible Application: Use
StepPhysics
during both Play tests and Edit time for versatile debugging and design workflows. - Partial World Simulation: Specify a subset of parts to simulate, enabling focused and efficient debugging.
Example Use Cases:
workspace:StepPhysics(1.0/60.0)
This advances all the parts in the workspace and any world models forward by 1/60th of a second. This is equivalent to a simulation step that is performed when a game is running normally.
workspace:StepPhysics(0.001)
This advances all the parts in the workspace and any world models forward by 1 millisecond. This is similar to a normal simulation step but advances things forward by a smaller time increment.
workspace:StepPhysics(1.0, {workspace.Part1})
This simulates the behavior of Part1 for 1 second while treating everything else in the workspace as fixed. Any parts connected to Part1 through constraints will be treated as anchored during the simulation; however, any parts in the same assembly will automatically be included in the simulation. Note that although the simulation will take many individual steps, the results will not be visualized until the duration is complete.
simulationJob = game:GetService("RunService").RenderStepped:Connect(function(dt)
workspace:StepPhysics(dt)
)
This advances the parts in the workspace forward by a time dt
for each render step that is performed. This will give the appearance that the simulation is “running” as normal but with more flexibility over the timescale of the simulation and the parts to be included in it.
Example Scenarios:
- Design Plugins: Create plugins that accelerate the design of physical mechanisms.
-
Debugging: Use
StepPhysics
during Play tests to debug and refine complex interactions. - Previewing Motion: Preview the motion of mechanisms during Edit time for immediate feedback as you adjust parameters.
- Natural Placement: Use physics to place objects naturally, like hanging a rope bridge or piling debris.
What’s Included When You “Step”?
When called during a play test, the StepPhysics
function simulates:
- Unanchored parts
- Animation tracks and rig positions
- Events such as PreSimulation, PostSimulation, and PreAnimation
During Edit time, only code defined in a plugin or executed from the command bar will run, ensuring scripts do not start automatically.
Example Plugin
To demonstrate the preview and debugging applications of this API, we are publishing a plugin which can be found here. With this plugin, you can preview the motion of a set of parts in the world by stepping the simulation forward in individual steps or running the simulation for a specified amount of time in a loop. While the simulation is running, you can adjust constraint parameters or add additional parts to the simulation to see how new components will interact with the system.
To start using this plugin:
- Click here
- Click on Get Plugin.
- Click on Try in Studio (Studio should open automatically).
- Click Install within the Toolbox window
- Click on the Plugins Tab
- And select the StepPhysics Demo (the GUIs will show up in the 3D viewport)
You can also search for the StepPhysics Demo plugin straight from the Toolbox in Studio.
Adding parts iteratively to the selective simulation set: start with the propeller blades, then add the base, and lastly add the humanoid.
Settling a pile of rectangular prisms for a more organic layout.
Settling a rope bridge to its natural rest state.
Leveraging this Plugin
The plugin also has the ability to copy itself into an experience’s ReplicatedStorage, allowing you to view the source code directly.
You can do this by clicking on Add Plugin Source Code to Replicated Storage (found in the top of the screen when having the StepPhysics Demo plugin enabled). After doing so, you should see a StepPhysics folder in Replicated Storage that contains the Script and ScreenGui used to make the plugin.
Our hope is that this plugin may inspire the development of more sophisticated and varied tools by the community. We encourage you to experiment with the StepPhysics
API and share your innovative plugins with the community.
Stay tuned for more updates and exciting features coming your way. As always, we value your feedback and are here to support you. If you have any questions, concerns, or requests, please let us know!
Best,
M0bsterLobster