0
\$\begingroup\$

I have a 3D game dungeon crawler game. It's procedurally generated. I have a bunch of prefab rooms that are used to put together this dungeon. When not in combat the player uses a navmesh to move around and that works great. When in combat we switch to a turn based grid based system where we use A* for moving in this grid.

In each room prefab I add some markers to help identify things. For example I add a start and end position marker which defines the center of the corner tiles mathematically for a grid. So each room can have its own little grid where battles are played out.

The orientation of the room, and hence the grid inside it, can be anything around the y axis which is up/down.

My A* path finding library needs to know row/col when asking for a path. I can get the position based on the mouse picking and need to convert that to file position if done inside the grid. Because the orientation of a room can be rotated what a row/col is changes from what I may have had in mind when I placed the start and end grid positions in the prefab.

I'm wondering how can I make getting this row/col based on mouse pick position unified no matter what position or rotation the room is.

\$\endgroup\$
1
  • \$\begingroup\$ This looks like the kind of geometry problem where some example images would be a big help, just to make sure we're understanding your problem correctly. \$\endgroup\$
    – DMGregory
    Sep 21, 2016 at 19:59

1 Answer 1

-1
\$\begingroup\$

So from what I understand (this game has one of those concepts that takes lots of word to describe until you see i picture and understand immediately) the player is in charge of changing the rotation of prefab rooms, or at least some system that you've built...

What i'd suggest is that you keep updating and change the data that you use for navigation as the data changes, this way no matter how much the rooms shuffle around the navmesh should always be up to date.

If thats not possible can you use another thread on the CPU to regenerate a new navmesh path and then swap it out for the old one every few seconds (turns, minutes, depending on how it changes)? I'm guessing that there is a way to figure out the cost between nodes so it should be possible to to keep going though every node to check what the cost is to it's new/old neighbors, If you keep this on the other thread and tell A* to only use the latest one you can even recycle the memory of old one, once you're sure that no one is using it, by using that for the new mesh while it is being generated.

Comment if this simply wouldn't work with your game and describe why? :)

\$\endgroup\$
4
  • 1
    \$\begingroup\$ He really just needs to get row/col under cursor. Everything else, including pathfinding and navmesh is irrelevant to the question. \$\endgroup\$
    – Kromster
    Sep 21, 2016 at 19:08
  • \$\begingroup\$ I only have access to my phone but I will draw a picture later today. The player doesn't generate anything though. When they walk into a dungeon that dungeon is generated by a bunch of room prefabs that get out together. I'll end up with a 2d mathematical represented grid in each room. That room can be rotated around y axis any angle. Now when the player click a "tile" to move I need to know what row and col that is for that grid so I can pass it along to the path finding lib. \$\endgroup\$
    – user441521
    Sep 21, 2016 at 19:09
  • \$\begingroup\$ If o manually place a room prefab in a map I can orient it so I know the grid would be at 0,0,0 and that rows is going positive in the z axis and cols is going positive in the x axis. The grid is then setup accordingly in code since the row and col count might not be the same it would matter that's right. But it you then rotate the room 90 degrees that code doesn't work anymore because it's swapping the rows and cols. \$\endgroup\$
    – user441521
    Sep 21, 2016 at 19:13
  • \$\begingroup\$ @user441521 if that is so, please remove irrelevant info from the question. \$\endgroup\$
    – Kromster
    Sep 21, 2016 at 19:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .