Hi, I’m trying to create an Anti-Bumps movement System.
When moving diagonally, the player avoids any block in his direction. making it go around this block smoothly and not colliding with it and getting stuck.
What I’ve already tried:
At the moment I decide to play raycast in all possible diagonal directions, but I can’t get the player to go around the obstacle without colliding.
Pathfinding is probably the approach you’d want to take here, maybe a custom algorithm
A first thought is to draw a line between where you are and where you want to be, assuming you have placed a node on every valid spot on the map (spots where there are no blocks). Find the nodes closest to either side of that line, and then traverse them from closest to farthest. Some challenges would of course be determining which node is “closest” since two nodes reflected on that line would be equidistant and drawing the line itself
Unsure: are you restricting their movement? Are you wanting this in real-time? I wouldn’t worry about the “best” way in terms of performance, as this would definitely be negligible.
This diagram looks great to base on, and regarding movements, yes I need this in real time, I’m using Roblox’s default movement system, I don’t decide to deactivate it and create one from scratch.
RunService.RenderStepped:Connect(function(dt)
local moveDirection = GetMovementDirection()
if moveDirection then
local newPosition = AntiBumps.MoveCharacter(RootPart, moveDirection)
if newPosition and (newPosition - RootPart.Position).magnitude > 0 then
local adjustedMoveDirection = (newPosition - RootPart.Position).unit
Humanoid:Move(adjustedMoveDirection, true)
end
end
end)
This will be much trickier in real-time, given that the player will have control. You could force the player to walk across the nodes as they travel diagonally, possibly, but what’s displayed in the video would definitely require a more complex solution