I am trying to achieve a FNaF 1 like movement script, where the (current placeholder) part gets moved to different areas.
I am struggling majorly with getting the part to move to branch off to different areas, for example, this is how Bonnie moves in FNaF 1.
Bonnie is able to pick two paths from the current location he’s in, I’m struggling to make it so he can choose between two paths instead of just one, moving it self works as long as it’s in a straight path, but when it comes to letting him choose a random number to move between two areas, I’m not sure how to go about it properly.
It currently changes the possible movement areas to a number due to the random number picker, then to nil and can’t be used by the table, what I want Bonnie to do is pick a random location out of the current possibilities he has.
I’ve attempted several methods and none have seemed to work. Such as using parts for the locations but the one I currently have is the closest I can get, though I’m still not sure how it’s supposed to work.
If I need to clarify anything further please let me know, any help would be much appreciated. I apologize for the confusing code.
Bonnie = function()
local movementPattern = {
["ShowStage"] = {-28.09, 5.094, -126.425},
["DiningHall"] = {-28.09, 1.422, -65.119},
["BackStage"] = {-78.163, 1.422, -94.832},
["LeftHall"] = {-40.066, 1.422, -27.349},
["LeftCorner"] = {-40.066, 1.422, 35.079},
["SupplyCloset"] = {-64.19, 1.422, -21.969},
["Door"] = {-34.309, 1.422, 3.5}
}
local currentArea = ""
local possibleAreas = {
[1] = {""},
[2] = {""}
}
local bonnie = workspace.Bonnie
local bonnieTime = 4.79
local ai = game.ReplicatedStorage.Values.AnimatronicAI.BonnieAI
local function roomCheck(area)
currentArea = area
if currentArea == "ShowStage" then
possibleAreas = {"DiningHall", "BackStage"}
end
if currentArea == "DiningHall" then
possibleAreas = {"BackStage", "LeftHall"}
end
if currentArea == "BackStage" then
possibleAreas = {"DiningHall", "LeftHall"}
end
if currentArea == "LeftHall" then
possibleAreas = {"SupplyCloset", "LeftCorner"}
end
if currentArea == "LeftCorner" then
possibleAreas = {"SupplyCloset", "Door"}
end
if currentArea == "SupplyCloset" then
possibleAreas = {"LeftHall", "LeftCorner"}
end
print(possibleAreas)
return currentArea
end
local function move(area)
if string.match(area, roomCheck(area)) then
local randomRoom = math.random(#possibleAreas)
print("Hello ".. randomRoom)
bonnie.Position = Vector3.new(unpack(movementPattern[randomRoom]))
end
print(currentArea)
end
move("ShowStage")
end