Hi,
I’m currently wondering how I would go about “drawing” a “rope” (part) between point A and B. Here’s an example of what I’d like to achieve:
As you can see, the rope doesn’t intersect with the grey part in the middle. While regularly drawing a rope from point A to B just ends up with:
A not so flattering outcome.
Given that context, how would I go about programming something like this? Is there any neat tricks to easily avoid intersections?
My first idea would be to shoot a raycast from point A (red dot) and see if it hits anything. If the raycast detects that the blue dot was hit, then immediately draw a straight line as that suggests no intersecting parts exist. However, if something else was hit, do something that would well, avoid said hit thing.
I honestly have no idea how to approach this problem so any help would be greatly appreciated.
1 Like
Try looking into “Path Finding”
, I haven’t tried it myself but I’m 80% sure it will help you
1 Like
Check this out, I got it from Roblox’s pathfinding documentation:
local TEST_DESTINATION = Vector3.new(100, 0, 100)
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local function followPath(destination)
-- Compute the path
local success, errorMessage = pcall(function()
path:ComputeAsync(character.PrimaryPart.Position, destination)
end)
if success and path.Status == Enum.PathStatus.Success then
-- Get the path waypoints
waypoints = path:GetWaypoints()
-- Detect if path becomes blocked
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
-- Check if the obstacle is further down the path
if blockedWaypointIndex >= nextWaypointIndex then
-- Stop detecting path blockage until path is re-computed
blockedConnection:Disconnect()
-- Call function to re-compute new path
followPath(destination)
end
end)
So they compute a path and if that path gets blocked they compute again and so on to get all desired waypoints in place and use those waypoints to create parts, that’s just some of the code you may want to check the rest at Character Pathfinding | Documentation - Roblox Creator Hub
1 Like
Apologies for the late reply.
The ideology is quite clever however a multitude of problems arise when the obstacle differs in size. Take this situation for example:
The green line represents the preferred outcome, while the red represents the outcome via path finding.
I haven’t dabbled a significant amount within path finding which doesn’t allow me to tackle this problem easily.
I’ve already tried to program this and this was the result:
It doesn’t look too bad, but of course, once the obstacle gets too large, the rope breaks:
I like the method you mentioned, but at the moment I lack the skill required to build my own reliable path finding system for ropes. I’ll be heading to sleep now; I’ll look back at this thread to see if anybody has another suggestion.
I appreciate the help, thank you.
1 Like