Page 1 of 1

PathFinding Creating graph

Posted: Mon Dec 16, 2013 3:36 pm
by Menyueru
I'm Working on Implementing an AI into my game, and i'm using an A* algorithm, i want to be able to dynamically create the graph with what we have in the space, i tried using

Code: Select all

game.Space.BroadPhase.QueryAccelerator.GetEntries(box, list);

for each node but this only checks if the box is inside the mesh bounding box not if it is actually colliding with it.

Is there anyway to check if the boundingbox is colliding with the mesh returned from the above code without having to actually add the box to the space??

Thanks in Advance

Re: PathFinding Creating graph

Posted: Mon Dec 16, 2013 6:26 pm
by Norbo
If you want to know collisions at the level of contact points, an actual collidable object will need to be tested. It's possible to avoid adding an object to the space, though. Use the NarrowPhaseHelper.Intersecting function if you know the involved collidables and all you need is the boolean collision state.

If you don't know the involved collidables, using GetEntries can collect them for you. If you want more than the boolean collision state, you can manually create the collision pair using NarrowPhasePairHandler.GetPairHandler.

Grabbing a pair handler directly requires a little bit of boilerplate to avoid leaking/triggering spurious events. You'll want to follow this pattern:

Code: Select all

                    var pairHandler = NarrowPhaseHelper.GetPairHandler(ref pair);
                    pairHandler.SuppressEvents = true;
                    pairHandler.UpdateCollision(0);
                    pairHandler.SuppressEvents = false;

                    //Analyze pair state. Check for contacts or whatever else.

                    pairHandler.CleanUp();
                    pairHandler.Factory.GiveBack(pairHandler);
(Making that less gross has been on my to-do list for a while now.)

Re: PathFinding Creating graph

Posted: Tue Dec 17, 2013 10:44 pm
by Menyueru
Hey thanks Norbo :D

i had tried with multiple raycasting but this is so much faster and better