Seat
A type of BasePart that a player character can 'sit' in. When a character touches an enabled Seat object, it will be attached to the part by a Weld and the default character scripts will play a sitting animation.
How do Seats work?
When a model containing a Humanoid and a BasePart called 'HumanoidRootPart' (generally a player character) touches a seat, a Weld is created between the seat and the part. The C0 and C1 properties are configured so that the character is welded 2 studs above the seat. This weld is named 'SeatWeld' and parented to the seat.
When sitting the Seat.Occupant property is set to the Humanoid that is 'sitting' in the seat. Furthermore the Humanoid.SeatPart property of the humanoid is set to the seat.
A character can also be forced to sit in a seat using the Seat:Sit() function.
There are two ways for a character to get out of a seat. When a player jumps, they are removed from the seat. However this can also be done manually by destroying the seat weld, for example:
seat:FindFirstChild("SeatWeld"):Destroy()
Note seats have a cooldown (currently 3 seconds) that is on a per-character per-seat basis. This means once a character has gotten out of a seat they cannot sit back on the same seat for 3 seconds. This cooldown behavior may change and should not be relied upon by developers.
What can Seats be used for?
Seats have a diverse range of uses, ranging from the obvious to the more unconventional.
- Creating chairs or benches without the need for any programming
- Allowing characters to 'sit' in moving objects such as vehicles without getting flung around
- Creating interfaces that are controlled by the character in the seat using the Seat.Occupant property
コードサンプル
local Players = game:GetService("Players")
local seat = Instance.new("Seat")
seat.Anchored = true
seat.Position = Vector3.new(0, 1, 0)
seat.Parent = workspace
local currentPlayer = nil
local function onOccupantChanged()
local humanoid = seat.Occupant
if humanoid then
local character = humanoid.Parent
local player = Players:GetPlayerFromCharacter(character)
if player then
print(player.Name .. " has sat down")
currentPlayer = player
return
end
end
if currentPlayer then
print(currentPlayer.Name .. " has got up")
currentPlayer = nil
end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(onOccupantChanged)
概要
プロパティ
Whether or not the seat is usable. If set to true, the seat will act as a normal part.
The humanoid that is sitting in the seat.
Sets the overall shape of the object.
Determines whether a part is immovable by physics.
The angular velocity of the part's assembly.
The center of mass of the part's assembly in world space.
The linear velocity of the part's assembly.
The total mass of the part's assembly.
A reference to the root part of the assembly.
Determines the type of surface for the Back face of a part (+Z direction).
Determines the type of surface for the Bottom face of a part (-Y direction).
Determines the color of a part.
Determines the position and orientation of the BasePart in the world.
Determines whether a part may collide with other parts.
Determines whether the part is considered during spatial query operations.
Determines if Touched and TouchEnded events fire on the part.
Determines whether or not a part casts a shadow.
Describes the world position in which a part's center of mass is located.
Describes the name of a part's collision group.
Determines the color of a part.
Indicates the current physical properties of the part.
Determines several physical properties of a part.
Used to enable or disable aerodynamic forces on parts and assemblies.
The actual physical size of the BasePart as regarded by the physics engine.
Determines the type of surface for the Front face of a part (-Z direction).
Determines the type of surface for the Left face of a part (-X direction).
Determines a multiplier for BasePart.Transparency that is only visible to the local client.
Determines whether a part is selectable in Studio.
Describes the mass of the part, the product of its density and volume.
Determines whether the part contributes to the total mass or inertia of its rigid body.
Determines the texture and default physical properties of a part.
The name of MaterialVariant.
Describes the rotation of the part in the world.
Specifies the offset of the part's pivot from its CFrame.
Describes the position of the part in the world.
Time since last recorded physics update.
Determines how much a part reflects the skybox.
Describes the smallest change in size allowable by the Resize method.
Describes the faces on which a part may be resized.
Determines the type of surface for the Right face of a part (+X direction).
The main rule in determining the root part of an assembly.
The rotation of the part in degrees for the three axes.
Determines the dimensions of a part (length, width, height).
Determines the type of surface for the Top face of a part (+Y direction).
Determines how much a part can be seen through (the inverse of part opacity).
方法
Forces the character with the specified Humanoid to sit in the Seat.
Apply an angular impulse to the assembly.
Apply an impulse to the assembly at the assembly's center of mass.
Apply an impulse to the assembly at specified position.
Returns whether the parts can collide with each other.
Checks whether you can set a part's network ownership.
Returns a table of parts connected to the object by any kind of rigid joint.
Return all Joints or Constraints that is connected to this Part.
Returns the value of the Mass property.
Returns the current player who is the network owner of this part, or nil in case of the server.
Returns true if the game engine automatically decides the network owner for this part.
Returns the base part of an assembly of parts.
Returns a table of all BasePart.CanCollide true parts that intersect with this part.
Returns the linear velocity of the part's assembly at the given position relative to this part.
Returns true if the object is connected to a part that will hold it in place (eg an Anchored part), otherwise returns false.
Changes the size of an object just like using the Studio resize tool.
Sets the given player as network owner for this and all connected parts.
Lets the game engine dynamically decide who will handle the part's physics (one of the clients or the server).
- IntersectAsync(parts : Instances,collisionfidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):Instance
Creates a new IntersectOperation from the overlapping geometry of the part and the other parts in the given array.
- SubtractAsync(parts : Instances,collisionfidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):Instance
Creates a new UnionOperation from the part, minus the geometry occupied by the parts in the given array.
- UnionAsync(parts : Instances,collisionfidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):Instance
Creates a new UnionOperation from the part, plus the geometry occupied by the parts in the given array.
Gets the pivot of a PVInstance.
Transforms the PVInstance along with all of its descendant PVInstances such that the pivot is now located at the specified CFrame.
イベント
BasePart から継承した イベントFires when a part stops touching another part as a result of physical movement.
Fires when a part touches another part as a result of physical movement.