PVInstance

Hiển Thị Bản Đã Lỗi Thời

*Nội dung này sẽ sớm có sẵn bằng ngôn ngữ bạn chọn.

Không Thể Tạo
Không Thể Duyệt

A PVInstance ("Position Velocity Instance") is an abstract class that cannot be created. It is the base for all objects that have a physical location in the world, specifically BaseParts and Models.

Tóm Tắt

Thuộc Tính

  • Không Sao Chép
    Không Thể Viết Kịch Bản
    Đọc Song Song
  • Không Sao Chép
    Không Thể Viết Kịch Bản
    Đọc Song Song

Phương Pháp

Thuộc Tính

Origin

Không Sao Chép
Không Thể Viết Kịch Bản
Đọc Song Song

Pivot Offset

Không Sao Chép
Không Thể Viết Kịch Bản
Đọc Song Song

Phương Pháp

GetPivot

Ghi Song Song

This function gets the pivot of a PVInstance. This is often used with PVInstance:PivotTo() to move a model.

Models and BaseParts are both PVInstances ("Position Velocity Instances") and so both have this function.


Lợi Nhuận

Mẫu mã

Simple Character Teleportation

-- This code should be placed in a LocalScript under StarterPlayerScripts
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local player = Players.LocalPlayer
local function doTeleport(_actionName, inputState, _inputObject)
local character = player.Character
if character and character.Parent and inputState == Enum.UserInputState.Begin then
-- Move the character 10 studs forwards in the direction they're facing
local currentPivot = character:GetPivot()
character:PivotTo(currentPivot * CFrame.new(0, 0, -10))
end
end
ContextActionService:BindAction("Teleport", doTeleport, true, Enum.KeyCode.F)

PivotTo

void

Transforms the PVInstance along with all of its descendant PVInstances such that the pivot is now located at the specified CFrame. This is the primary function that should be used to move Models via scripting.

BaseParts are moved in this way by having their CFrame transformed by the necessary offset. Models are moved in this way by having their Model.WorldPivot transformed by the necessary offset.

Note that for efficiency purposes, Object.Changed events are not fired for Position and Orientation of BaseParts moved in this way; they are only fired for CFrame.

When calling PivotTo on Models, the offsets of the descendant parts and models are cached, such that subsequent calls to PivotTo on the same model do not accumulate floating point drift between the parts making up the model.

Models and BaseParts are both PVInstances ("Position Velocity Instances") and so both have this function.

Tham Số

targetCFrame: CFrame

The CFrame that the PVInstance pivot should equal after moving it.


Lợi Nhuận

void

Mẫu mã

Simple Character Teleportation

-- This code should be placed in a LocalScript under StarterPlayerScripts
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local player = Players.LocalPlayer
local function doTeleport(_actionName, inputState, _inputObject)
local character = player.Character
if character and character.Parent and inputState == Enum.UserInputState.Begin then
-- Move the character 10 studs forwards in the direction they're facing
local currentPivot = character:GetPivot()
character:PivotTo(currentPivot * CFrame.new(0, 0, -10))
end
end
ContextActionService:BindAction("Teleport", doTeleport, true, Enum.KeyCode.F)

Sự Kiện