I’m attempting to set up a system for rendering a fire hose that travels from the connection point on the wall to the player in a semi-realistic manner (not just clipping through whatever is in the way in a straight line). What I’m trying currently is to use pathfinding, which although giving decent results sometimes generates ridiculous, unrealistic paths that exceed the limit I set on the number of waypoints, and this is the biggest problem for me.
Unfortunately, the Pathfinding service is not very flexible and doesn’t contain many options besides a few agent parameters for defining your path, so I’m not sure what else I can do to make the result more favorable. The code I’m using for the above system is:
local pathfinding = game:GetService("PathfindingService")
local player = game:GetService("Players").LocalPlayer
local run = game:GetService("RunService")
local path = pathfinding:CreatePath({AgentRadius = 1, AgentHeight = 1, AgentCanJump = true})
local bracket = workspace.HoseConnectionRL.Bracket
function SetEndpoints(part, point1, point2)
part.Size = Vector3.new(part.Size.X, (point1 - point2).magnitude, part.Size.Z)
part.CFrame = CFrame.new(point1:Lerp(point2, 0.5), point2) * CFrame.Angles(math.rad(90), 0, 0)
end
wait(1)
while true do
wait()
path:ComputeAsync(bracket.Position, player.Character.PrimaryPart.Position)
local wp = path:GetWaypoints()
if #wp < 100 then
workspace.HoseParts:ClearAllChildren()
local last = bracket
for _, waypoint in pairs(wp) do
local part = workspace.HoseTemplate:Clone()
part.Parent = workspace.HoseParts
SetEndpoints(part, last.Position + (-last.CFrame.UpVector * (last.Size.Y/2)), waypoint.Position)
last = part
end
end
end
(this code uses some really awful scripting practices which I’m aware of, but it was just lazily written to test the idea)
In this example, the hose template part I had created is a cylinder which I was unable to flip in a way that the forward face was actually the front face of the cylinder mesh, so I’m using the bottom face instead, hence -CFrame.UpVector
.
I’ve been trying to look for ways of either improving this method or using another method that generates better results. The only other way of doing this that I’ve recognized so far is actually creating the hose out of physics parts attached by ball in socket joints with a limited angle, but I was hoping there would be alternative solutions before relying on physics. Does anyone have any ideas/advice?