Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 24, 2024, 11:57:37 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)What's a good way to handle pathfinding while accounting for my sprite's size?
Pages: [1]
Print
Author Topic: What's a good way to handle pathfinding while accounting for my sprite's size?  (Read 706 times)
thecodethinker
Level 0
*


View Profile WWW
« on: February 02, 2016, 04:58:10 PM »

I'm trying to test out A* pathfinding and I set it up to use some vertices in a navmesh as nodes but, when my sprite moves around corners it's texture overlaps with the corner of the navmesh.

What's a good way for me to prevent this?

Thanks in advance!
Logged

There is no permanence for the knowledge seeker.

qMopey
Level 6
*


View Profile WWW
« Reply #1 on: February 03, 2016, 09:49:42 PM »

As in you don't want the sprite to be able to go over nodes for which it is too big? I'd add in an additional check within the A* algorithm that does a "userdata callback", or whatnot. A* calls this function and passes a reference to the userdata, in your case the sprite, asking if this move is valid. Then you can do whatever custom collision detection check you like to specify if this piece of the graph is traversable or not.

The callback thing might be overkill and perhaps you can just hard-code this check directly into your A* implementation -- whichever you choose is up to your and your project.

An example would be each node contains a float that represents maximum scale, and any sprite over this scale size cannot travel on that particular node.
Logged
bateleur
Level 10
*****



View Profile
« Reply #2 on: February 05, 2016, 03:41:19 AM »

How easy this is to fix depends on whether you need to support multiple sizes of sprite and whether your map has places which are passable to some sizes but not others.

If you only have one size of sprite then your basic problem is that your navmesh is wrong in the sense that it doesn't reflect the places the character can actually go. The fixes qMopey suggests will work, or it might be easier to just fix the mesh, depending on how you generated it.

If you need multiple sizes then the problem is you need a different mesh for each. However, if there are no narrow passages (passable only to smaller sprites) you can hack around this requirement by generating the mesh for the largest size of sprite and then letting smaller sprites take shortcuts if they can "see" their destination node early.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic