Anti-Bumps Movement System

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 have so far: video:
https://gyazo.com/5733c01f53fcdd0eeed009b5ed848390

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.

video:
https://gyazo.com/0e7272c4bf2c4eef7ca372ade39fd732

Obs:
Any help would be appreciated, I’m doing this for a personal project, thanks.

drawing of what I’m referring to

1 Like

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

1 Like

Hello, I thought about doing this, but this system is for the player character, and would it be the best way to do this?

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.

Here is a diagram of what I meant. Sorry for the poor quality, but it should illustrate the point well enough

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.

my main code to move the player

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

Yes, I need this in real time so that it can bypass any object it finds in its path, anyway I’ll try with pathfinding, thanks for the tip!

1 Like

use a custom pathfinding system
try reading into this: A* Pathfinding Module

Thanks everyone for your help, I managed to do this now.

You should probably post how you solved it so people who have similar questions know how to achieve this.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.