NPC chase logic

Alright this is gonna be a bit hard to explain in words so I’m just going to draw you some pictures.




Any help on how I can solve this is appreciated, thanks

1 Like

Maybe make invisible part(s) that when the NPC touches, it makes it go in a certain direction?

1 Like

Where would I put these invisible parts exactly?

1 Like

I would make a raycast to the player, and if the raycast isn’t obstructed, make the NPC follow the player. Also make the raycast update every time the player moves. But once that raycast gets obstructed, create an invisible part. Have the NPC stop following the player, and make the NPC go to that part. Once it reaches the part, fire the raycasts again, and if the raycast is obstructed, the NPC doesn’t follow the player.

2 Likes

If there is a dead end, as in the image, then put the parts where the NPC is going to turn the corner. For example

The blue is where the parts should be.

1 Like

I’m pretty sure that that would just end in the same situation drawn above.

2 Likes

I don’t want this to be made just for dead ends, but for any turn basically, so pretend that the dead end isn’t even there.

1 Like

Then maybe make a path of invisible parts across the map, and make it so that when the NPC’s RayCast hits one of those parts, it checks for a tag that is a certain name like IsNpc, and then makes the NPC rotate a set amount of degrees? Like you can add an IntValue to each of the parts which represents how much you will rotate the NPC. This might take awhile though since you have to calculate how much the NPC needs to rotate for each part it touches. I don’t really have any other solutions that I can think of.

1 Like

bump please help me ahhhhhhhhh

1 Like

This might be overcomplicated but you could try to get the player’s AssemblyLinearVelocity and estimate where they are going to be and continue in that direction until the player is found or a timeout is done.

1 Like

That would work for the situation above although if the hallway had another singular turn it would backfire. However I will use this to maximize my AI realism so thanks

1 Like

You could also try to use PathfindingService but I’m assuming you don’t want to do that.

1 Like

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