Empty
Empty
Empty
Roblox physics allows developers to create realistic interactions and movements within their games. Understanding and manipulating physics components can greatly enhance gameplay and immersion.
Components | Description | Use Case |
---|---|---|
BodyForce | Applies a constant force to a part. | Simulating continuous thrust, such as a rocket engine. |
BodyVelocity | Maintains a specified velocity by adjusting the applied force. | Keeping a vehicle or platform moving at a constant speed. |
BodyPosition | Moves a part to a specified position and keeps it there. | Creating a part that moves to and holds a target position, like an elevator. |
BodyGyro | Maintains a part’s orientation using torque. | Stabilizing a part's rotation, such as keeping a rocket upright. |
BodyAngularVelocity | Applies a constant rotational speed to a part. | Rotating a part at a constant speed, like a spinning fan. |
Basic Physics Examples
BodyVelocity
This component applies a continuous force to maintain a specific velocity in a chosen direction, overriding other forces acting on the part.
Roblox Studio
local parentPart = script.Parent -- Reference to the parent part
local velocity = Instance.new("BodyVelocity")
velocity.Velocity = Vector3.new(0, 50, 0) -- Move upward
velocity.MaxForce = Vector3.new(0, 10000, 0) -- Apply force on Y axes
velocity.Parent = parentPart -- Apply the BodyVelocity to the parent part
Velocity
This sets an initial upward velocity. The velocity will decrease over time due to external forces like gravity and friction.
Roblox Studio
local parentPart = script.Parent -- Reference to the parent part
parentPart.Velocity = Vector3.new(0, 50, 0) -- Move upward
BodyForce
This component applies a continuous force in a specific direction, often used to counteract gravity or simulate constant acceleration. Unlike BodyVelocity, it does not directly control speed but rather influences movement by adding a consistent force.
Roblox Studio
local parentPart = script.Parent -- Reference to the parent part
local force = Instance.new("BodyForce")
force.Force = Vector3.new(0, 5000, 0) -- Apply upward force of 5000 on the Y-axis
force.Parent = parentPart -- Apply the BodyForce to the parent part
BodyGyro
This continuously applies force to move the part to the specified position and keeps it there, overriding any external forces.
Roblox Studio
local parentPart = script.Parent -- Reference to the parent part
local gyro = Instance.new("BodyGyro")
gyro.CFrame = CFrame.Angles(math.rad(45), math.rad(30), 0) -- Desired rotation
gyro.MaxTorque = Vector3.new(4000, 4000, 4000) -- Maximum torque applied on each axis
gyro.P = 3000 -- Power
gyro.Parent = parentPart -- Apply the BodyGyro to the parent part
BodyPosition
This continuously applies force to move the part to the specified position and keeps it there, counteracting any external forces.
Roblox Studio
local parentPart = script.Parent -- Reference to the parent part
local position = Instance.new("BodyPosition")
position.Position = Vector3.new(0, 5, 0) -- Target position
position.MaxForce = Vector3.new(4000, 4000, 4000) -- Maximum force applied to reach the target position
position.D = 1000 -- Damping
position.P = 5000 -- Power
position.Parent = parentPart -- Apply the BodyPosition to the parent part
BodyAngularVelocity
This continuously applies torque to maintain a constant rotational speed around the Y-axis, overriding any resistive forces.
Roblox Studio
local parentPart = script.Parent -- Reference to the parent part
local angularVelocity = Instance.new("BodyAngularVelocity")
angularVelocity.AngularVelocity = Vector3.new(0, 2, 0) -- Rotate around Y-axis
angularVelocity.MaxTorque = Vector3.new(0, 10000, 0) -- Maximum torque applied
angularVelocity.Parent = parentPart -- Apply the BodyAngularVelocity to the parent part