local Ship = game.Workspace.TheShip
local StartingBall = Ship.StartingBall
local EndingBall = Ship.EndingBall
for i,v in pairs(game.Workspace:GetChildren()) do
if v:FindFirstChild("Cities") then
for i,city in pairs(v.Cities:GetChildren()) do
if city.Value.BillboardCity.NomeCit.Text == "VENICE" then
StartingBall.Value = v
end
if city.Value.BillboardCity.NomeCit.Text == "CONSTANTINOPLE" then
EndingBall.Value = v
end
end
end
end
local ClosestBallToEndGoal
local PreviousBall = StartingBall
local CurrentBall = StartingBall
local Arrived = false
repeat
wait(3)
local ClosestMagnitude = 100000
for i,v in pairs(CurrentBall.Value.NeighboringWaypoints:GetChildren()) do
local NeighboringBall = v.Value
print("Current ball "..CurrentBall.Value.Name)
if NeighboringBall == EndingBall.Value then
print("ARRIVED AT "..EndingBall.Value.Name)
Arrived = true
PreviousBall.Value = CurrentBall.Value
CurrentBall.Value = EndingBall.Value
Ship.CFrame = CFrame.lookAt(Ship.Position,CurrentBall.Value.Position)
Ship.Position = CurrentBall.Value.Position
else
print("Neighbor " .. NeighboringBall.Name , "Previous " .. PreviousBall.Value.Name)
if NeighboringBall ~= PreviousBall.Value then
print(math.ceil((NeighboringBall.Position - EndingBall.Value.Position).magnitude) , math.ceil(ClosestMagnitude))
if (NeighboringBall.Position - EndingBall.Value.Position).magnitude < ClosestMagnitude then
print(NeighboringBall.Name.." is closer")
ClosestMagnitude = (NeighboringBall.Position - EndingBall.Value.Position).magnitude
ClosestBallToEndGoal = NeighboringBall
end
end
end
end
if Arrived == false then
PreviousBall.Value = CurrentBall.Value
CurrentBall.Value = ClosestBallToEndGoal
Ship.CFrame = CFrame.lookAt(Ship.Position,CurrentBall.Value.Position)
Ship.Position = CurrentBall.Value.Position
print("ship is at "..CurrentBall.Value.Name)
end
print("=================================")
until Arrived == true
“NeighboringBalls” is a folder inside each ball, which has objectValues telling which neighboring balls the ship can travel to next.
The problem is the ship cant really figure out that it should go around the continent instead of just running into the wall.
Do you guys have any idea on how this problem can be solved?