Ok, so I know the title may seem like this is something very basic, but I have reached a problem that I have no idea how to solve; I have a fish that is swimming in a pond, it does this by generating random Vector3 positions and CFrame lerping towards them. However, I want to implement a feature to prevent the fish from just plain swimming through parts and out of the map.
Is there a way in rbx.lua that would let me find the positions of the edges of parts, or does anyone know of an easier method that would let me achieve the same thing?
If anyone want's to see the script, here it is:
while wait() do
local part = script.Parent
marker = Vector3.new(128.015, 2.109, 95.71)
local pos = part.CFrame
local increment = Vector3.new(math.random(-10,10),0,math.random(-10,10))
local newPos = part.CFrame + increment
for i = 0,1,0.01 do
part.CFrame = pos:lerp(newPos, i)
part.CFrame = CFrame.new(part.CFrame.p, increment)
wait(0.01)
end
end
