Walkable areas for non-characters

Started by Atelier, Mon 02/07/2012 19:05:10

Previous topic - Next topic

Atelier

What would be the best way to mimic a walkable area but for things that are not characters? For example, you have a car, boat or person (defined by a struct/array) which has an x and y value on the map, but cannot go beyond a boundary enclosing the map (impassable area). It would be simpler if this boundary was a line, but how about a curved/irregular one? I can only think that you'd need to define all the coordinates which are impassable and stop the entity from ever going on them.

Also, how about restricted areas within the outer boundary, like a rock or something? Would this mean I'd need to write a pathfinding algorithm? Internal boundaries aren't really important though for what I need. Here's a really bad diagram to illustrate, with grey areas being impassable:



Thanks.

DoorKnobHandle

I'm not quite sure what you're talking about in the last paragraph about restricted areas within the outer boundary.

Three ways:

(1) You make that boat or whatever a character, just don't allow any kind of interaction with it.
(2) You use an invisible character, move that character (using walkable areas) and just set the struct position equal to that of the invisible character.
(3) You write your own pathfinding algorithm.

Khris

Quote from: Atelier on Mon 02/07/2012 19:05:10I can only think that you'd need to define all the coordinates which are impassable and stop the entity from ever going on them.
You can do the same thing as AGS: use a sprite and GetPixel.

If you want good AI you have to use pathfinding, the alternative is for the entity to go straight towards the target until they hit the impassable area.

Atelier

Sorry, I'll explain more, I didn't want to use characters because there will likely be about 20 different units on the screen. It's a small simulator to reenact tactics of the American Civil War for a History project. By internal boundaries, I meant that the battlefield is surrounded by an outer boundary, but within that outer boundary could be small objects which are also impassible, like a rock, but are surrounded by walkable areas.

Quote from: Khris on Mon 02/07/2012 19:55:54
Quote from: Atelier on Mon 02/07/2012 19:05:10I can only think that you'd need to define all the coordinates which are impassable and stop the entity from ever going on them.
You can do the same thing as AGS: use a sprite and GetPixel.

Ah ok. So, I could draw the battlefield how it will appear in-game, then create an overlay where I draw the impassable regions in one colour and leave the rest transparent (or vice versa)? Then I just check the overlay sprite using GetPixel to see if the region you direct a unit to is walkable (has no pixels)?

Khris

You'd use a DynamicSprite that's invisible to the player but yes, that's the idea.
If you need pathfinding though, I'd use characters. Just create as much dummy characters as you need and handle them using the character[] array.

SMF spam blocked by CleanTalk