Empty
Empty
Empty
RunService can be used for animation. It also allows handling real-time updates and frame-by-frame control.
Events | Details |
---|---|
Heartbeat | Fires every frame after the physics simulation has completed. |
PostSimulation | Fires every frame after the physics simulation has completed. |
PreAnimation | Fires every frame prior to the physics simulation but after rendering. |
PreRender | Fires every frame prior to the frame being rendered. |
PreSimulation | Fires every frame prior to the physics simulation. |
RenderStepped | Fires every frame prior to the frame being rendered. |
Stepped | Fires every frame prior to the physics simulation. |
RunService vs wait()
Empty
Empty
Empty
local part = Instance.new("Part")
part.Size = Vector3.new(4, 4, 4)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.Parent = workspace
local speed = 5 -- studs per second
spawn(function()
while true do
wait(0.033) -- Approximate wait time for 30 FPS (Frame per second)
part.Position = part.Position + Vector3.new(speed * 0.033, 0, 0)
end
end)
wait() is less precise and can vary slightly in timing, leading to less smooth animations.
RunService vs TweenService
Empty
Empty
Empty
- Ideal for smooth, predictable animations.
- Best for simple property transitions.
- Easy to use with built-in easing styles.
- TweenService leverages mechanisms similar to what RunService provides to ensure smooth animations, including the use of delta time for frame-independent interpolation of properties.
Empty
Empty
Empty
- Suitable for real-time, dynamic updates.
- Allows frame-by-frame control.
- Versatile for various tasks beyond animations.
- RenderStepped is tied to the rendering process, which occurs on the client side, it is restricted to LocalScripts.
RunService Use Case Example
Examples | Details |
---|---|
Custom Render Logic | 3D GUIs: Create and update 3D GUI elements that must follow parts or characters in the game world. |
Player-Exclusive Features | Local Game Mechanics: Implement features or mechanics that should only affect the local player, such as local-only particle effects or lighting changes. |
Camera Manipulation | Dynamic Camera Control: Smoothly update the camera's position, orientation, or focus based on player actions or game events to create a more immersive experience. |