What does positioning look like now? Is it better than before or still really off?
Still really off. There’s no difference.
Can you try making it create a part where the raycast hits? It would be easier to visualize what’s going wrong.
I have just tested it and :MoveTo is performing around 20x better.
Code I used:
local Model = Instance.new("Model")
local Part = Instance.new("Part")
Part.Anchored = true
Part.Parent = Model
local startingTime = os.clock()
for i = -50, 50 do
for j = -50, 50 do
Model:MoveTo(Vector3.new(i, 0, j))
end
end
print(os.clock() - startingTime)
local startingTime = os.clock()
for i = -50, 50 do
for j = -50, 50 do
local currentPosition = Vector3.new(i, 100, j)
local raycast = workspace:Raycast(currentPosition, Vector3.yAxis * -100)
Model:PivotTo(CFrame.new(raycast.Position))
end
end
print(os.clock() - startingTime)
Model.Parent = workspace
Performance:
MoveTo(): 0.000988899999356363
Raycasts: 0.02166600000055041
There is a huge part in the middle of my baseplate. I don’t even check if the raycast is valid in the raycast loop and :MoveTo still performs better.
Are you directly positioning the models to those positions? If you could show me your updated Main code and Generation code that would help. All of those raycasts look valid though.
I position the models by using raycast and it detects the y axis of the terrain so it doesn’t clip through it.
local GENERATION = {}
function GENERATION:GenerateModel(Table)
if typeof(Table) ~= "table" then
error("NOT A TABLE!!!")
return
end
local Model : Part = Instance.new("Part")
Model.Anchored = true
Model.Size = Vector3.new(8,8,8)
local Position = Table[2]
local NewCFrame
if typeof(Position) == "Vector3" then
NewCFrame = CFrame.new(Position)
else
local NewCFrame = CFrame.new(Vector3.new(Position[1], Position[2], Position[3]))
end
Model.CFrame = NewCFrame
Model.Parent = workspace:WaitForChild("Foilage"):WaitForChild(Table[1].Parent.Name)
return Model
end
return GENERATION
for Count = 1, S_V do
local Result = RAYCAST:GetCast({{STATUS.MapX, STATUS.MapZ}, STATUS.CheckHeight})
local M_F : Folder
local Success, Fail = pcall(function()
M_F = STATUS[ARGS[1]]
end)
local Model = M_F:GetChildren()[math.random(1, #M_F:GetChildren())]
local ARGS = string.split(M_F.Name, "_")
local NewVector3 = STATUS[ARGS[1].."_YOffset"]
task.spawn(function()
if Result and Result.Instance:IsA("Terrain") then
GENERATION:GenerateModel({Model, Result.Position})
end
end)
task.wait()
end
Does it only work for parts?
No, I just replaced the Model code to part
So does the code work now?
I believe I need a more efficient code that will load the meshpart unfortunately.
These are the ones that does have children
You need to add the YOffset now.
Code:
for Count = 1, S_V do
local Result = RAYCAST:GetCast({{STATUS.MapX, STATUS.MapZ}, STATUS.CheckHeight})
local M_F: Folder
local Success, Fail = pcall(function()
M_F = STATUS[ARGS[1]]
end)
local Model = M_F:GetChildren()[math.random(1, #M_F:GetChildren())]
local ARGS = string.split(M_F.Name, "_")
local NewVector3 = STATUS[ARGS[1].."_YOffset"]
task.spawn(function()
if Result and Result.Instance:IsA("Terrain") then
GENERATION:GenerateModel({Model, Result.Position + NewVector3})
end
end)
task.wait()
end
This is still happening
I’m starting to believe the issue is the model itself and not the code
I’ve figured it out,
local Model = ModelInstance:Clone() do
local CF, Size = Model:GetBoundingBox()
local NewCFrame = CFrame.new(Position.X, (Size.Y / 2.275) + Position.Y, Position.Z)
local Angles = CFrame.Angles(0,math.rad(math.floor(math.random(0, 90))), 0)
Model:PivotTo(NewCFrame * Angles)
end
Good work, sorry for not replying earlier, I forgot to. And thank you for setting mine as the solution!
Add about 100 parts and try to moveto at the bottom. Is it still fast?