PVInstance

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

ไม่สามารถสร้าง
ไม่สามารถเรียกดู

A PVInstance ("ตำแหน่งความเร็วตัวอย่าง") เป็นคลาสที่ไม่สามารถสร้างได้เป็นพื้นฐานสำหรับวัตถุทั้งหมดที่มีสถานที่ทางกายภาพในโลกโดยเฉพาะ BaseParts และ Models

สรุป

คุณสมบัติ

  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน
  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน

วิธีการ

  • เขียนพร้อมๆ กัน

    รับจุดศูนย์กลางของ PVInstance .

  • PivotTo(targetCFrame : CFrame):()

    เปลี่ยน PVInstance พร้อมกับบรรดาลูกหลานทั้งหมดของมัน PVInstances ทำให้จุดศูนย์กลางอยู่ที่ตําแหน่งที่ระบุแล้ว CFrame

คุณสมบัติ

Origin

ไม่ซ้ำ
ไม่สามารถเขียนสคริปต์
อ่านพร้อมๆ กัน

Pivot Offset

ไม่ซ้ำ
ไม่สามารถเขียนสคริปต์
อ่านพร้อมๆ กัน

วิธีการ

GetPivot

เขียนพร้อมๆ กัน

ฟังก์ชันนี้ได้รับจุดศูนย์กลางของ PVInstance นี้มักใช้กับ PVInstance:PivotTo() เพื่อย้ายโมเดล

Models และ BaseParts ทั้งสองเป็น 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

()

เปลี่ยน PVInstance พร้อมกับบรรดาลูกหลานทั้งหมดของมัน PVInstances ทำให้จุดศูนย์กลางอยู่ที่ตําแหน่งที่ระบุแล้ว CFrameนี่คือฟังก์ชันหลักที่ควรใช้เพื่อย้าย Models scripting

BaseParts ถูกย้ายไปในลักษณะนี้โดยมีการเปลี่ยนแปลง CFrame โดยค่าส่วนลบที่จำเป็นModels ถูกย้ายไปในลักษณะนี้โดยมีการเปลี่ยนแปลง Model.WorldPivot โดยค่าส่วนลบที่จำเป็น

โปรดทราบว่าเพื่อวัตถุประสงค์ในการประหยัด กิจกรรม Object.Changed จะไม่ถูกยิงสําหรับ Position และ Orientation ของ BaseParts ย้ายในลักษณะนี้; พวกเขาจะถูกยิงเฉพาะสําหรับ CFrame เท่านั้น

เมื่อเรียก PivotTo บน Models ออฟเซ็ตของส่วนย่อยและโมเดลจะถูกบันทึกไว้ ดังนั้นการโทรต่อไปยัง PivotTo บนโมเดลเดียวกันจะไม่สะสมความผิดพลาดของจุดทศนิยมระหว่างส่วนที่ประกอบขึ้นเป็นโมเดล

Models และ BaseParts ทั้งสองเป็น PVInstances ("ตัวอย่างความเร็วตำแหน่ง") และทั้งสองมีฟังก์ชันนี้

พารามิเตอร์

targetCFrame: CFrame

The 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)

อีเวนต์