Classe motore
Model
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Sommario
Proprietà
Metodi
AddPersistentPlayer(playerInstance: Player):() |
BreakJoints():() |
breakJoints():() |
MakeJoints():() |
makeJoints():() |
RemovePersistentPlayer(playerInstance: Player):() |
SetPrimaryPartCFrame(cframe: CFrame):() |
TranslateBy(delta: Vector3):() |
Membri ereditati
Membri ereditati da PVInstance: 4
Membri ereditati da Instance: 57
Membri ereditati da Object: 6
Ereditata da
Campioni di codice
Istanziamento di Modello di Base
local function groupObjects(objectTable)
local model = Instance.new("Model")
for _, object in pairs(objectTable) do
object.Parent = model
end
return model
end
local objects = {
Instance.new("Part"),
Instance.new("Part"),
}
groupObjects(objects)Riferimento API
Proprietà
PrimaryPart
Campioni di codice
Lanciare i Dadi
-- Crea un modello di dado con due metà e attaccale insieme
local diceModel = Instance.new("Model")
diceModel.Name = "ChanceCube"
local diceTop = Instance.new("Part")
diceTop.Size = Vector3.new(4, 2, 4)
diceTop.Position = Vector3.new(0, 1, 0)
diceTop.Color = Color3.new(0, 0, 1)
diceTop.Parent = diceModel
local diceBottom = diceTop:Clone()
diceBottom.Position = Vector3.new(0, -1, 0)
diceBottom.Color = Color3.new(1, 0, 0)
diceBottom.Parent = diceModel
local weld = Instance.new("WeldConstraint")
weld.Part0 = diceTop
weld.Part1 = diceBottom
weld.Parent = diceModel
-- Metti il dado in aria sopra l'origine dello spazio di lavoro (non richiede una parte primaria)
diceModel.Parent = workspace
diceModel:PivotTo(CFrame.new(0, 10, 0))
-- Assegna la parte primaria prima della simulazione fisica
-- Senza questa riga, lo script restituirà sempre la stessa cosa e la bounding box del modello non cambierà orientamento
diceModel.PrimaryPart = diceTop
-- Aspetta un attimo prima di lanciare il dado (lascia che si stabilizzi sul pavimento)
for i = 5, 1, -1 do
print("Lanciando i dadi in...", i)
task.wait(1)
end
diceTop:ApplyAngularImpulse(Vector3.new(15000, 1000, 5000))
diceTop:ApplyImpulse(Vector3.new(0, 3000, 0))
task.wait(1)
-- Aspetta che il lancio sia completato
while diceTop.AssemblyLinearVelocity.Magnitude > 0.1 or diceTop.AssemblyAngularVelocity.Magnitude > 0.1 do
task.wait()
end
-- Ottieni l'orientamento del dado, impattato dalla parte primaria
local orientation = diceModel:GetBoundingBox()
if orientation.YVector.Y > 0.5 then
print("È il ragazzo!")
else
print("È sua madre!")
endWorldPivot
Campioni di codice
Ripristina Pivot
local function resetPivot(model)
local boundsCFrame = model:GetBoundingBox()
if model.PrimaryPart then
model.PrimaryPart.PivotOffset = model.PrimaryPart.CFrame:ToObjectSpace(boundsCFrame)
else
model.WorldPivot = boundsCFrame
end
end
resetPivot(script.Parent)Metodi
AddPersistentPlayer
BreakJoints
breakJoints
GetExtentsSize
Restituzioni
Campioni di codice
Dimensione GetExtents di Modello
local model = Instance.new("Model")
model.Parent = workspace
local RNG = Random.new()
for _ = 1, 5 do
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(RNG:NextNumber(0.05, 5), RNG:NextNumber(0.05, 5), RNG:NextNumber(0.05, 5))
part.Parent = model
end
print(model:GetExtentsSize())GetModelCFrame
GetModelSize
GetPrimaryPartCFrame
GetScale
Restituzioni
Campioni di codice
Sostituire un modello di ricambio utilizzando PivotTo e ScaleTo
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Trova tutti i modelli con il tag che vogliamo sostituire
local items = CollectionService:GetTagged("Tree")
local newModel = ReplicatedStorage.FancyTreeReplacementModel
for _, item in items do
-- Crea il nuovo elemento e scalalo / posizionalo dove si trovava il vecchio
local newItem = newModel:Clone()
newItem:ScaleTo(item:GetScale())
newItem:PivotTo(item:GetPivot())
-- Aggiungi lo stesso tag alla sostituzione
CollectionService:AddTag(newItem, "Tree")
-- Elimina il vecchio elemento e genitore il nuovo
newItem.Parent = item.Parent
item:Destroy()
endMakeJoints
makeJoints
move
MoveTo
Parametri
Restituzioni
()
Campioni di codice
Muovi Modello
local START_POSITION = Vector3.new(-20, 10, 0)
local END_POSITION = Vector3.new(0, 10, 0)
local model = Instance.new("Model")
model.Parent = workspace
local part1 = Instance.new("Part")
part1.Size = Vector3.new(4, 4, 4)
part1.Position = START_POSITION
part1.Anchored = true
part1.BrickColor = BrickColor.new("Bright yellow")
part1.Parent = model
local part2 = Instance.new("Part")
part2.Size = Vector3.new(2, 2, 2)
part2.Position = START_POSITION + Vector3.new(0, 3, 0)
part2.Anchored = true
part2.BrickColor = BrickColor.new("Bright blue")
part2.Parent = model
model.PrimaryPart = part1
model.Parent = workspace
local obstruction = Instance.new("Part")
obstruction.Name = "Obstruction"
obstruction.Size = Vector3.new(10, 10, 10)
obstruction.Position = Vector3.new(0, 10, 0)
obstruction.Anchored = true
obstruction.BrickColor = BrickColor.new("Bright green")
obstruction.Parent = workspace
task.wait(3)
model:MoveTo(END_POSITION)moveTo
RemovePersistentPlayer
ResetOrientationToIdentity
SetIdentityOrientation
SetPrimaryPartCFrame
TranslateBy
Parametri
Restituzioni
()
Campioni di codice
Modello TranslateBy
local START_POSITION = Vector3.new(-20, 10, 0)
local END_POSITION = Vector3.new(0, 10, 0)
local model = Instance.new("Model")
local part1 = Instance.new("Part")
part1.Size = Vector3.new(4, 4, 4)
part1.CFrame = CFrame.new(START_POSITION) * CFrame.Angles(0, math.rad(45), 0)
part1.Anchored = true
part1.BrickColor = BrickColor.new("Giallo brillante")
part1.Parent = model
local part2 = Instance.new("Part")
part2.Size = Vector3.new(2, 2, 2)
part2.CFrame = part1.CFrame * CFrame.new(0, 3, 0)
part2.Anchored = true
part2.BrickColor = BrickColor.new("Blu brillante")
part2.Parent = model
model.PrimaryPart = part1
model.Parent = workspace
local obstruction = Instance.new("Part")
obstruction.Name = "Ostruzione"
obstruction.Size = Vector3.new(10, 10, 10)
obstruction.Position = Vector3.new(0, 10, 0)
obstruction.Transparency = 0.5
obstruction.Anchored = true
obstruction.BrickColor = BrickColor.new("Verde brillante")
obstruction.Parent = workspace
task.wait(3)
-- usa TranslateBy per spostare il modello nell'ostruzione
model:TranslateBy(END_POSITION - START_POSITION)