WorldRoot

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

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

ไม่สามารถสร้าง

คลาสเบื้องหลังนี้ให้ API สำหรับคำถามและการจำลองทางภาพ 3D ทั้งหมด เช่น Workspace และ WorldModel

สรุป

คุณสมบัติ

คุณสมบัติรับทอดมาจากModel
  • การรักษาความปลอดภัยของปลั๊กอิน
    อ่านพร้อมๆ กัน

    ตั้งค่าระดับรายละเอียดในแบบจำลองสำหรับประสบการณ์ที่มีการเปิดใช้งานการสตรีมมิ่งด้วยตัวอย่าง

  • อ่านพร้อมๆ กัน

    ควบคุมพฤติกรรมการสตรีมโมเดลบน Models เมื่อการสตรีมเครื่องมือเปิดใช้งาน

  • อ่านพร้อมๆ กัน

    ส่วนหลักของ Model หรือ nil ถ้าไม่ได้ตั้งค่าไว้อย่างชัดเจน

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

    สมบัติสินค้าเฉพาะที่ใช้เพื่อปรับแต่งรุ่นรอบ ๆ แกนของมัน การตั้งค่าคุณสมบัตินี้จะย้ายความเคลื่อนไหวของเครื่องชั่งเมื่อ Model/ScaleTo ถูกเรียกบนมัน

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    กำหนดตำแหน่งที่โค้งของ Model ซึ่ง ไม่ มีชุด Model.PrimaryPart ตั้งอยู่

คุณสมบัติรับทอดมาจากPVInstance
  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน
  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน

วิธีการ

  • ArePartsTouchingOthers(partList : Instances,overlapIgnored : number):bool

    กลับ true หากมีส่วนใดส่วนหนึ่งใน BasePart สัมผัสกับส่วนอื่น

  • Blockcast(cframe : CFrame,size : Vector3,direction : Vector3,params : RaycastParams):RaycastResult?
    เขียนพร้อมๆ กัน

    สร้างรูปร่างบล็อกในทิศทางที่กำหนดและส่งคืน RaycastResult หากรูปร่างตีโจมตี BasePart หรือ Terrain เซลล์

  • BulkMoveTo(partList : Instances,cframeList : Array,eventMode : Enum.BulkMoveMode):void

    ย้ายตารางขนาด BaseParts ไปยังตารางขนาด CFrames

  • GetPartBoundsInBox(cframe : CFrame,size : Vector3,overlapParams : OverlapParams):Instances
    เขียนพร้อมๆ กัน

    กลับรายการรายการที่มีขอบเขต ตรงกัน ในกล่องที่ระบุ

  • GetPartBoundsInRadius(position : Vector3,radius : number,overlapParams : OverlapParams):Instances
    เขียนพร้อมๆ กัน

    กลับรายการรายการที่มีชิ้นส่วนอยู่ภายในเขต กรอบเหลี่ยมของวงกลมที่กำหนดไว้

  • GetPartsInPart(part : BasePart,overlapParams : OverlapParams):Instances
    เขียนพร้อมๆ กัน

    กลับรายการผู้ให้บริการที่มีพื้นที่ว่างของพื้นที่ที่ได้รับการแชร์

  • IKMoveTo(part : BasePart,target : CFrame,translateStiffness : number,rotateStiffness : number,collisionsMode : Enum.IKCollisionsMode):void
    การรักษาความปลอดภัยของปลั๊กอิน

    ย้ายส่วนที่กำหนดไว้ไปยังสถานที่ที่กำหนดโดยอัตราสมทบทางกลศาสตร์ที่กลับกันโดยไม่ต้องย้ายไปที่นั่นโดยตรงเพื่อให้แน่ใจว่าข้อต่อ ข้อจํากัด หรือการชนที่ร่วมมือใด ๆ จะเหลืออยู่ในระดับที่พอใจ

  • Raycast(origin : Vector3,direction : Vector3,raycastParams : RaycastParams):RaycastResult?
    เขียนพร้อมๆ กัน

    ใช้ลำแสงโดยใช้ต้นไม้, ทิศทาง, และตัวเลือก RaycastParams จากนั้นจะกลับมาที่ RaycastResult หากวัตถุหรือพื้นที่ที่เป็นไปได้สัมผัสกับลำแสง

  • Shapecast(part : BasePart,direction : Vector3,params : RaycastParams):RaycastResult?
  • Spherecast(position : Vector3,radius : number,direction : Vector3,params : RaycastParams):RaycastResult?
    เขียนพร้อมๆ กัน

    โยนรูปร่างกลมในทิศทางที่กำหนดและส่งคืน RaycastResult หากรูปร่างตีโจมตี BasePart หรือ Terrain เซลล์

  • StepPhysics(dt : number,parts : Instances):void
    การรักษาความปลอดภัยของปลั๊กอิน

    ขับเคลื่อนการจำลองสำหรับชิ้นส่วนในโลกไปข้างหน้าโดยใช้เวลาเพิ่มเติมที่กำหนดและชุดตั้งค่าอื่น ๆ ของ BaseParts

วิธีการรับทอดมาจากModel
  • AddPersistentPlayer(playerInstance : Player):void

    ตั้งค่ารุ่นนี้ให้เป็นรุ่นที่แข็งแกร่งสำหรับผู้เล่นที่กำหนด Model.ModelStreamingMode ต้องถูกตั้งไว้ให้เป็น PersistentPerPlayer เพื่อให้การเปลี่ยนแปลงพฤติกรรมเป็นผลมาจากการเพิ่ม

  • รวมถึงคำอธิบายของระดับที่มีทุกส่วนของแบบ

  • กลับขนาดของกล่องชุดที่เล็กที่สุดที่มี BaseParts ใน Model ที่ตรงกับ Model.PrimaryPart ตั้งค่า

  • กลับสิ่งที่เป็น Player วัตถุทั้งหมดที่วัตถุนี้มีความยืนยันสำหรับ การเรียกคืนของวิธีนี้จาก Script หรือ LocalScript ต่างกันไปตามว่าวิธีนี้เรียกได้จาก

  • กลับขนาดเครื่องชี้วัดที่กำหนดไว้ของแบบจำลองซึ่งเริ่มต้นด้วย 1 สำหรับแบบจำลองที่สร้างขึ้นใหม่และจะเปลี่ยนแปลงเมื่อมันถูกเคลื่อนผ่านโดย Model/ScaleTo

  • MoveTo(position : Vector3):void

    ย้าย PrimaryPart ไปยังตำแหน่งที่กำหนด หากไม่มีส่วนหลักได้ระบุไว้ จะใช้ส่วนหลักของแบบจำลอง

  • RemovePersistentPlayer(playerInstance : Player):void

    ทำให้รุ่นนี้ไม่มีอยู่ต่อไปสำหรับผู้เล่นที่กำหนด Model.ModelStreamingMode ต้องการตั้งค่าให้เป็น PersistentPerPlayer เพื่อให้พฤติกรรมเปลี่ยนแปลงเป็นผลมาจากการลบ

  • ScaleTo(newScaleFactor : number):void

    ตั้งค่าตัวปรับขนาดของแบบจำลองโดยปรับขนาดและตำแหน่งของบรรพบุรุษทั้งหมดให้มีตัวปรับขนาดของแบบจำลองที่สมเหตุสมผลเมื่อตัวปรับขนาดอยู่ที่ 1

  • TranslateBy(delta : Vector3):void

    เปลี่ยน Model โดยใช้การเคลื่อนที่ Vector3 ที่กำหนดไว้ เพื่อเก็บความตรงของโมเดล หาก BasePart หรือ 1> Class.Terrain1> ม

วิธีการรับทอดมาจากPVInstance
  • เขียนพร้อมๆ กัน

    รับ pivot ของ Class.PVInstance

  • PivotTo(targetCFrame : CFrame):void

    แปลง PVInstance พร้อมกับบรรพบุรุษทั้งหมดของมัน PVInstances เพื่อให้ pivot ตอนนี้อยู่ที่ CFrame ที่กำหนด

คุณสมบัติ

วิธีการ

ArePartsTouchingOthers

ArePartsTouchingOthers กลับ true หากอย่างน้อยหนึ่งใน BasePart กำลังสัมผัสกับอื่น ๆ อีกสองส่วนถือเป็น "สัมผัส" หากอยู่ภายในระยะสนามประกาศ overlapIgnored

หากไม่มีส่วนใด จะได้รับการตอบกลับว่าเป็น false

พารามิเตอร์

partList: Instances

รายการรายการตรวจสอบว่ามีรายการใดในรายการที่สัมผัสกับรายการอื่น ๆ ที่ไม่ได้อยู่ในรายการหรือไม่

overlapIgnored: number

ระยะการเกี่ยวข้างของชิ้นส่วนที่ไม่ได้รับการพิจารณาก่อนที่จะพิจารณาว่าชิ้นส่วนนั้นสัมพันธ์กัน

ค่าเริ่มต้น: 0.000199999995

ส่งค่ากลับ

จริงหรือไม่ ถ้าและเท่านั้นหากมีใครสักคนใน parts ใน partList สัมผัสกับส่วนอื่น (ส่วนอื่นไม่ในส่วนList) ปลอมหากไม่มีส่วนผ่าน

ตัวอย่างโค้ด

The code block below demonstrates how to use WorldRoot:ArePartsTouchingOthers() to check if parts in a list are touching any parts in the workspace not in the list.

First the script creates two square parts that overlap 1 stud, Part1 and Part2. Then, it prints the value returned by ArePartsTouchingOthers() when Part1 is passed in partList at three different overlap values: 0, 0.999, and 1. The first two times ArePartsTouchingOthers() is called return false because the overlap values are less than the distance that Part1 and Part2 overlap. The third call returns true because the overlap value is equal to the distance that the parts overlap.

Checking for Touching Parts

local part1 = Instance.new("Part")
part1.Name = "Part1"
part1.Anchored = true
part1.Transparency = 0.5
part1.Color = Color3.fromRGB(185, 100, 38)
part1.Size = Vector3.new(2, 2, 2)
part1.Position = Vector3.new(0, 4, 0)
part1.Parent = workspace
local part2 = Instance.new("Part")
part2.Name = "Part2"
part2.Anchored = true
part2.Transparency = 0.5
part2.Color = Color3.fromRGB(200, 10, 0)
part2.Size = Vector3.new(2, 2, 2)
part2.Position = Vector3.new(0, 5, 0)
part2.Parent = workspace
local partList = { part1 }
print(workspace:ArePartsTouchingOthers(partList, 0)) -- True
print(workspace:ArePartsTouchingOthers(partList, 0.999)) -- True
print(workspace:ArePartsTouchingOthers(partList, 1)) -- False

Blockcast

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

กำหนดรูปร่างบล็อกในทิศทางที่กำหนดและส่งความสามัคคีครั้งแรกด้วย BasePart หรือ Terrain เซลล์ นี่คือการใช้งานของ WorldRoot:Raycast() ใน

ในขณะที่วิธีนี้ไม่ตรวจจับ WorldRoot:GetPartsInPart() ที่ BaseParts เป็นตัวผสานรูปร่าง

หากตรวจพบการโจมตี RaycastResult จะถูกส่งกลับมาพร้อมกับข้อมูลการโจมตี สมบัติสถาน Distance จะแทนที่ระยะที่ต้องเดินทางไปยังการโ

วิธีนี้จะแสดงข้อผิดพลาดหากมีการส่งผิดพลาด CFrame ขนาดหรือการป้อนทิศทาง

พารามิเตอร์

cframe: CFrame

ตําแหน่งเริ่มต้นและการหมุนของรูปร่างบล็อค

size: Vector3

ขนาดของรูปร่างบล็อกโครงใน studs ขนาดสูงสุดคือ 512 studs

direction: Vector3

ทิศทางของ shapecast มีความเข้มขนาดเป็นระยะทางสูงสุดที่รูปร่างสามารถเดินทางได้ ระยะทางสูงสุดคือ 1024 สตัด

ค่าเริ่มต้น: "RaycastParams{IgnoreWater=false, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

ส่งค่ากลับ

ประกอบด้วยผลลัพธ์ของการดำเนินการ shapecast หรือ nil หากไม่มีเซลล์ BasePart หรือ Terrain ที่เหมาะสม

ตัวอย่างโค้ด

Casts a block and returns the first collision with a BasePart or Terrain. Prints the properties of the RaycastResult if a result was hit.

Blockcasting

local Workspace = game:GetService("Workspace")
local function castBlock()
-- The initial position and rotation of the cast block shape
local originCFrame = CFrame.new(Vector3.new(0, 50, 0))
-- The size of the cast block shape
local size = Vector3.new(6, 3, 9)
-- The direction the block is cast in
local direction = -Vector3.yAxis
-- The maximum distance of the cast
local distance = 50
-- Cast the block and create a visualization of it
local raycastResult = Workspace:Blockcast(originCFrame, size, direction * distance)
if raycastResult then
-- Print all properties of the RaycastResult if it exists
print(`Block intersected with: {raycastResult.Instance:GetFullName()}`)
print(`Intersection position: {raycastResult.Position}`)
print(`Distance between block's initial position and result: {raycastResult.Distance}`)
print(`The normal vector of the intersected face: {raycastResult.Normal}`)
print(`Material hit: {raycastResult.Material.Name}`)
else
print("Nothing was hit")
end
end
-- Continually cast a block every 2 seconds
while true do
castBlock()
task.wait(2)
end

BulkMoveTo

void

ฟังก์ชันนี้ย้ายตารางขนาด BaseParts ไปยังตารางขนาด CFrames โดยไม่จำเป็นต้องเปิดใช้งานสมบัติสินค้าเรียบร้อยสำหรับแต่

ตัวอักษรที่สามช่วยให้คุณสามารถปรับปรุงการทำงานข

หมายเหตุว่าคุณควรใช้ให้คุณสมบัตินี้เฉพาะในกรณีที่คุณแน่ใจว่าการเคลื่อนที่ส่วนใดส่วนหนึ่งเป็นข้อจํากัดในรหัสของคุณ การตั้งค่าคุณสมบัติ CFrame ของแต่ละส่วน

พารามิเตอร์

partList: Instances
cframeList: Array
ค่าเริ่มต้น: "FireAllEvents"

ส่งค่ากลับ

void

GetPartBoundsInBox

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

WorldRoot:GetPartBoundsInBox() ส่งคืนรายการของชิ้นส่วนที่มีขอบชุดที่ซ้องกับกล่องที่มีขนาดอธิบายโดยใช้ศูนย์กลาง ( Datatype.CFrame และขนาด ( CFrame ) ที่ระบุโดยใช้ศู

ตามที่เน้นไว้ วิธีการเรียกคำถามทางอาคารเฉพาะจะพิจารณาปริมาณการกำหนดขอบเขตของชิ้นส่วนโดยไม่ใช้พื้นที่จริงของพวกเขา นี่อาจเป็นสิ

วิธีนี้ใช้ OverlapParams ตัวเพื่ออธิบายส่วนที่ใช้ซ้ำของคำถามทางอาคาร, เช่น รายการรวมหรือรวมออก, จำนวนผลลัพธ์สูงสุ

พารามิเตอร์

cframe: CFrame

ตำแหน่งของศูนย์กลางของปริมาณเสียงกล่องที่จะถูกขอ

size: Vector3

ขนาดของกล่องที่ให้ต้องการ

overlapParams: OverlapParams

ประกอบด้วยส่วนที่ใช้ซ้ำได้ของค่าตัวละคริดตัวละคร

ค่าเริ่มต้น: "OverlapParams{MaxParts=0, Tolerance=0, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

ส่งค่ากลับ

Instances

หนึ่งรายการของ Class.BasePart|BaseParts ซึ่งตรงกับคำถามทางพื้นที่

GetPartBoundsInRadius

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

WorldRoot:GetPartBoundsInRadius() ส่งคืนสามสิบหกส่วนที่มีขอบเขตซึ่ง มุมมองของกลม ซ้องกับลูกบอลที่มีขนาดอธิบายโดยใช้ Vector3 และรัศมี ( 0> number0> )

ตามที่เน้นไว้ วิธีการเรียกคำถามทางอาคารเฉพาะจะพิจารณาปริมาณการกำหนดขอบเขตของชิ้นส่วนโดยไม่ใช้พื้นที่จริงของพวกเขา นี่อาจเป็นสิ

วิธีนี้ใช้ OverlapParams ตัวเพื่ออธิบายส่วนที่ใช้ซ้ำของคำถามทางอาคาร, เช่น รายการรวมหรือรวมออก, จำนวนผลลัพธ์สูงสุ

พารามิเตอร์

position: Vector3

ตำแหน่งศูนย์กลางของปริมาณลูกศรที่ให้

radius: number

รัศมีของเสียงที่ให้ไว้สำหรับการค้นหา

overlapParams: OverlapParams

ประกอบด้วยส่วนที่ใช้ซ้ำได้ของค่าตัวละคริดตัวละคร

ค่าเริ่มต้น: "OverlapParams{MaxParts=0, Tolerance=0, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

ส่งค่ากลับ

Instances

หนึ่งรายการของ Class.BasePart|BaseParts ซึ่งตรงกับคำถามทางพื้นที่

GetPartsInPart

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

WorldRoot:GetPartsInPart() กลับส่งคืนรายการของชิ้นส่วนที่มีพื้นที่ว่างอยู่กับชิ้นส่วนที่ต้องการ (ซึ่งต้องมีใน Class.WorldRoot เดียวกับชิ้นส่วนที่จะถูกขอ)

ตามที่กล่าวไว้ ตรวจสอบ ปริมาณที่แน่นอน ที่เป็นปริมาณที่แน่นอนโดยการใ

วิธีนี้ใช้ OverlapParams ตัวเพื่ออธิบายส่วนที่ใช้ซ้ำของคำถามทางอาคาร, เช่น รายการรวมหรือรวมออก, จำนวนผลลัพธ์สูงสุ

พารามิเตอร์

part: BasePart

ส่วนที่มีปริมาณต้องตรวจสอบกับส่วนอื่น

overlapParams: OverlapParams

ประกอบด้วยส่วนที่ใช้ซ้ำได้ของค่าตัวละคริดตัวละคร

ค่าเริ่มต้น: "OverlapParams{MaxParts=0, Tolerance=0, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

ส่งค่ากลับ

Instances

หนึ่งรายการของ Class.BasePart|BaseParts ซึ่งตรงกับคำถามทางพื้นที่

IKMoveTo

void
การรักษาความปลอดภัยของปลั๊กอิน

คุณสมบัตินี้ย้ายชิ้นส่วนที่กำหนดไว้ไปยังสถานที่ที่กำหนดโดย kinematics ย้อนกลับ แทนที่จะย้ายไปที่นั่นโดยตรงเพื่อให้แน่ใจว่าข้อต่อใด ��

แปลความแข็งแกร่ง เป็นตัวเลขระหว่าง 0 และ 1 ที่ระบุว่าอย่างไรอย่างน้อยหนึ่งในตำแหน่งของชิ้นส่วนจะตรงกับตำแหน่งของชิ้นส่วนเป้าหมาย CFrame หมุนค

เช่น:

  • หากความแข็งแกร่งและความหมุนแข็งแกร่งเป็นสองสิ่งที่เท่ากันกับ 1 ส่วนจะย้ายไปยัง CFrame เป้าหมายโดยเฉพาะไม่ว่าจะมีข้อจํากัดทางกายภาพใด ๆ
  • หากความหนาและความหมุนเป็นสองสิ่งที่เท่ากันกับ 0.5 ส่วนจะพยายามที่จะย้ายไปยังเป้าหมาย CFrame ที่แน่นอน แต่อาจถูกผลักออกจากเส้นทางโดยข้อจํากัดทางกายภาพบนเส้นทาง
  • หากความหนาแน่นและความหนาแน่นหมุนเป็นสองสิ่งที่เท่ากันกับ 0 จะไม่มี CFrame เป้าหมายจะได้รับการละเลยและข้อจํากัดทางกายภาพจะแก้ไขสําหรับเป้าหมายที่ตําแหน่งที่มันอยู่

พารามิเตอร์

part: BasePart

กำลังย้ายส่วน

target: CFrame

ตําแหน่งที่จะย้ายชิ้นส่วนที่กําหนด

translateStiffness: number

ตัวเลขระหว่าง 0 และ 1 กำหนดว่าอย่างไรอย่างรุนแรงเพื่อจับตำแหน่งของชิ้นส่วนให้ตรงกับตำแหน่งของชิ้นส่วนเป้าหมาย CFrame

ค่าเริ่มต้น: 0.5
rotateStiffness: number

ตัวเลขระหว่าง 0 และ 1 ที่ระบุว่าอย่างไรอย่างรุนแรงที่จะจับคู่การหมุนของส่วนหนึ่งกับส่วนหมุนเป้าหมาย CFrame

ค่าเริ่มต้น: 0.5
collisionsMode: Enum.IKCollisionsMode

ช่วยให้คุณสามารถระบุว่าวัตถุใดที่ควรได้รับผลกระทบโดยความละเอียดทางกายภาพ

ค่าเริ่มต้น: "OtherMechanismsAnchored"

ส่งค่ากลับ

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

สร้างลำแสงโดยใช้ต้นไม้, ทิศทาง, และตัวเลือก RaycastParams หากพบเซลล์ BasePart หร

หมายเหตุว่าความยาว (แมกนิจูด) ของเวกเตอร์ทิศทางเป็นสิ่งสำคัญเนื่องจากวัตถุ / พื้นผิวที่อยู่ไกลออกไปจากความยาวของมั

วิธีนี้ไม่ได้ใช้วัตถุ Datatype.Ray แต่ส่วนประกอบด้านความเป็นเอกของมันสามารถยืมได้จาก Ray และ Ray.Origin

พารามิเตอร์

origin: Vector3

จุดเริ่มต้นของลำแสง

direction: Vector3

เวกเตอร์ทิศทางของลำแสง หมายเหตุว่าความยาวของเวกเตอร์นี้สำคัญเนื่องจากชิ้นส่วน/พื้นผิวที่อยู่ไกลออกไปจากความยาวจะไม่ได้รับการทดสอบ

raycastParams: RaycastParams

ตัวอักษรที่ใช้ในการระบุความเหมาะสมในการโค้งผ่านเรย์คาสท์ หากไม่ได้ระบุให้ จะใช้ค่าเริ่มต้นทั้งหมดโดยอ้างอิงจากทุกส่วน และ Terrain น้ำจะไม่ได้รับการเพิกเฉย

ค่าเริ่มต้น: "RaycastParams{IgnoreWater=false, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

ส่งค่ากลับ

ประกอบด้วยผลลัพธ์ของการดำเนินการ raycast หรือ nil หากไม่มีเซลล์ BasePart หรือ Terrain ที่เหมาะสม

ตัวอย่างโค้ด

Casts a ray and returns the first collision with a BasePart or Terrain. Prints the properties of the RaycastResult if a result was hit.

Raycasting

local Workspace = game:GetService("Workspace")
local function castRay()
-- The origin point of the ray
local originPosition = Vector3.new(0, 50, 0)
-- The direction the ray is cast in
local direction = -Vector3.yAxis
-- The maximum distance of the ray
local distance = 50
-- Cast the ray and create a visualization of it
local raycastResult = Workspace:Raycast(originPosition, direction * distance)
if raycastResult then
-- Print all properties of the RaycastResult if it exists
print(`Ray intersected with: {raycastResult.Instance:GetFullName()}`)
print(`Intersection position: {raycastResult.Position}`)
print(`Distance between ray origin and result: {raycastResult.Distance}`)
print(`The normal vector of the intersected face: {raycastResult.Normal}`)
print(`Material hit: {raycastResult.Material.Name}`)
else
print("Nothing was hit")
end
end
-- Continually cast a ray every 2 seconds
while true do
castRay()
task.wait(2)
end

Shapecast

พารามิเตอร์

part: BasePart
direction: Vector3
ค่าเริ่มต้น: "RaycastParams{IgnoreWater=false, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

ส่งค่ากลับ

Spherecast

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

ใส่รูปร่างกลมในทิศทางที่กำหนดและส่งการโคจรครั้งแรกด้วย BasePart หรือ Terrain เซลล์ นี่คือเหมือนกับวิธีที่ WorldRoot:Raycast() โคจรเส้นสา

ในขณะที่วิธีนี้ไม่ตรวจจับ WorldRoot:GetPartsInPart() ที่ BaseParts เป็นตัวผสานรูปร่าง

หากตรวจพบการโจมตี RaycastResult จะถูกส่งกลับมาพร้อมกับข้อมูลการโจมตี สมบัติสถาน Distance จะแทนที่ระยะที่ต้องเดินทางไปยังการโ

วิธีนี้จะแสดงข้อผิดพลาดหากมีการส่งค่ารัศมีหรือทิศทางไปยังผิดพลาด

พารามิเตอร์

position: Vector3

ตําแหน่งเริ่มต้นของรูปร่างกลม

radius: number

รัศมีของรูปร่างกลมโฉมในสตุ๊ก. รัศมีสูงสุดคือ 256 สตุ๊ก

direction: Vector3

ทิศทางของ shapecast มีความเข้มขนาดเป็นระยะทางสูงสุดที่รูปร่างสามารถเดินทางได้ ระยะทางสูงสุดคือ 1024 สตัด

ค่าเริ่มต้น: "RaycastParams{IgnoreWater=false, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

ส่งค่ากลับ

ประกอบด้วยผลลัพธ์ของการดำเนินการ shapecast หรือ nil หากไม่มีเซลล์ BasePart หรือ Terrain ที่เหมาะสม

ตัวอย่างโค้ด

Casts a sphere and returns the first collision with a BasePart or Terrain. Prints the properties of the RaycastResult if a result was hit.

Spherecasting

local Workspace = game:GetService("Workspace")
local function castSphere()
-- The initial position of the cast spherical shape
local originPosition = Vector3.new(0, 50, 0)
-- The radius of the cast spherical shape in studs
local radius = 10
-- The direction the sphere is cast in
local direction = -Vector3.yAxis
-- The maximum distance of the cast
local distance = 50
-- Cast the sphere and create a visualization of it
local raycastResult = Workspace:Spherecast(originPosition, radius, direction * distance)
if raycastResult then
-- Print all properties of the RaycastResult if it exists
print(`Sphere intersected with: {raycastResult.Instance:GetFullName()}`)
print(`Intersection position: {raycastResult.Position}`)
print(`Distance between sphere's initial position and result: {raycastResult.Distance}`)
print(`The normal vector of the intersected face: {raycastResult.Normal}`)
print(`Material hit: {raycastResult.Material.Name}`)
else
print("Nothing was hit")
end
end
-- Continually cast a sphere every 2 seconds
while true do
castSphere()
task.wait(2)
end

StepPhysics

void
การรักษาความปลอดภัยของปลั๊กอิน

ขยายเวลาจำลองสำหรับอินสแตนซ์ข

พารามิเตอร์

dt: number

จำนวนเวลาที่จะถูกจำลอง ตัวอ้างนี้ต้องเป็นตัวเลขที่บวก มูลค่าที่ใหญ่ขึ้นจะเพิ่มเวลาทำงานของฟังก์ชันนี้

parts: Instances

ค่าย่อหลายชิ้นที่จะถูกจำลอง ชุดนี้ต้องมีตัวอย่างที่เป็นของ BasePart เท่านั้น ชุดอื่น ๆ จะได้รับการเพิกเฉย

ค่าเริ่มต้น: "{}"

ส่งค่ากลับ

void

ตัวอย่างโค้ด

Simulates the parts in the workspace for a fixed period of time by calling the StepPhysics function once per frame until a specified time has elaspsed.

StepPhysics

local RunService = game:GetService("RunService")
-- Optional array of parts to simulate; otherwise all parts will be simulated
local partsToSimulate = {
workspace.Part
}
local function simulateParts(duration)
local time = 0.0
local stepJob
stepJob = RunService.RenderStepped:Connect(function(dt)
if time + dt > duration then
dt = duration - time
end
workspace:StepPhysics(dt, partsToSimulate)
time = time + dt
if time >= duration then
stepJob:Disconnect()
end
end)
end
-- Simulate workspace parts for 5 seconds, stepping the parts once per frame
simulateParts(5.0)

อีเวนต์