PVInstance

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
無法瀏覽

A PVInstance (「位置速度實例」)是一個抽象類別,無法創建。它是所有擁有世界物理位置的對象的基礎,具體來說是 BasePartsModels

概要

屬性

方法

  • 平行寫入

    獲得 PVInstance 的軸心。

  • PivotTo(targetCFrame : CFrame):()

    將 以及所有其子孫 轉換為指定的 位置,使旋轉點現在位於指定的 位置。

屬性

Origin

未複製
無法建立指令碼
平行讀取

Pivot Offset

未複製
無法建立指令碼
平行讀取

方法

GetPivot

平行寫入

這個功能得到 PVInstance 的中心點。這通常與 PVInstance:PivotTo() 一起使用,以移動模型。

ModelsBaseParts 都是 PVInstances (「位置速度實例」),因此兩者都擁有此功能。


返回

範例程式碼

This code sample is a simple teleport script that moves your character 10 studs forwards in the direction you're currently facing when you press the F key. It does so by getting the current pivot with PVInstance:GetPivot() and calling PVInstance|PivotTo to move the character forwards.

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

()

將 以及所有其子孫 轉換為指定的 位置,使旋轉點現在位於指定的 位置。這是應該用於通過指令碼化移動 Models 的主要功能。

BaseParts 以此方式移動,因為它們的 CFrame 被必要的偏移偏移值。Models 以這種方式移動它們的 Model.WorldPivot 被必要的偏移偏移值。

請注意,為了效率目的,Object.Changed事件不會在PositionOrientationBaseParts移動時發射;它們只會在CFrame發射。

當在 PivotTo 上呼叫 Models 時,子部件和模型的偏移被緩存,因此後續對 PivotTo 在同一模型上的呼叫不會累積模型組成部件之間的浮點漂移。

ModelsBaseParts 都是 PVInstances (「位置速度實例」),因此兩者都擁有此功能。

參數

targetCFrame: CFrame

旋轉後的 CFrame 應該等於移動後的 PVInstance

預設值:""

返回

()

範例程式碼

This code sample is a simple teleport script that moves your character 10 studs forwards in the direction you're currently facing when you press the F key. It does so by getting the current pivot with PVInstance:GetPivot() and calling PVInstance|PivotTo to move the character forwards.

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)

活動