Tell me how to make an object simultaneously be an object that searches for a path and can be an obstacle?
For example, there are several players on the stage and they need to find a way to the place where the cursor points, but it is also necessary that these players do not collide or pass through each other, they need to go around each other.
The event “Push away is not suitable” because it is necessary for players to go around each other.
What have you tried? You can assign both behaviors to an object. You might need to disable the obstacle pathfinder behavior of the object being moved prior to trying to move it. The player may see itself as an obstacle otherwise. You could then reenable it afterwards.
Constantly refreshing a pathfinder can use a lot of resources. You could probably reduce it by checking for distance between players or maybe between moving players. Depending on the complexity of your scene, you may need to find ways to reduce the updates to a minimum.
I tried using two behaviors at once.
If the player moves towards the “obstacle” object, he goes around it, and if towards the player with two behaviors, the player goes right through the player
How often were you triggering the pathfinder move action? It takes a sort of snapshot each time, it creates a list of nodes or path . It then follows that path. If another player is moving then the path needs to be updated as often as needed. Otherwise, the player would just continue on the path.
I’ve always wanted a way to check if something is in the path. I want to test using the nodes list with a ray cast. It might not help you but it made me curious. Do a ray cast from one node to the node plus 1.
To run it on each frame, it just needs to be on an event without any conditions. If you move the players to a position based on a mouse click then you might need to save that position in variables. And then use those variables for the destination.
I wouldn’t recommend starting a new path on each frame unless the scene is fairly simple.
You could probably do something that checks the distance between objects and only “refresh” the path when the objects are close.
If more than 1 object is moving then the last section might need a for each object. I tested with just one object. As is, it would deactivate the behavior of both objects at the same time. A for each object would do 1 at a time. I don’t have the time to test it but I think that should work.
Add the for each object as a subevent and place the actions inside it.
zfoxx is using the pathfinder behavior. The seperate object action would push the objects away from each other but then the pathfinder would put the objects back on their paths.
I wonder if you could combine that with a pathfinder move action.
Objects collide.
Seperate objects
Refresh the path
You would still need a for each object and disable the obstacle behavior before and then enable afterwards.
I’ve said it once and ill say it again, use the boids behavior
it’s a replacement for pathfinding that pushes away the two objects when in collision with each other
well using the separate 2 objects pushes the first object from the second object like:
player walks into moving object, the moving object then retains movement from pathfinder behavior, but the player is stopped because they cant move into said wall object. so there for the player is pushed away from the wall, or another object you add.
“Separate objects” is not quite suitable.
When using “Separate objects” players leak through each other or, if there is a large crowd, they can push each other into an area from which it is impossible to escape
Yes, when using boids, you will need to delete the pathfinding and pathfinding obstacle behaviors. then just use the “intent to move forward” action in the events and the behavior will make them avoid each other automatically