Object layer and isometric map

Post your help queries and engine programming questions here

Object layer and isometric map

Postby Killersan » Sun Mar 01, 2015 12:21 pm

Hello again. I would like to ask about Your opinion on how to make functionality described below.
Character can move on the map tiles which are not occupied and by occupied i mean where any kind of object is placed, like river, tree, rock, house, etc. but while two characters will fight each other, then ranged skills like fireball should be able to move through occupied tiles like river and maybe rock, but it shouldn't move through the tree, house, etc. so the lower ones should not be crossable by player but crossable by ranged skills and the higher ones should not be crossable by characters nor ranged skills.

Can You please give me an advice how could I achieve it without losing too much performance.
I'll be very thankfull for any kind of input and propositions.
User avatar
Killersan
 
Posts: 24
Joined: Sat Jun 21, 2014 1:45 pm

Re: Object layer and isometric map

Postby robaldred » Mon Mar 02, 2015 3:10 pm

Hello, it's pretty easy to do really.
You can define a tileChecker callback for the path component of an entity. This callback method can do checks on a entity against any data stored against the tile.

Here's an example that might work for you.
I'm going to assume you have different classes for each of your various entities.

Like... TreeEntity, RockEntity, HouseEntity
These classes could extend a base class that you define to give shared behaviour, I'm going to assume you have understand of OO and inheritance here.

You can determine what entity is on the map either by it's class or by it's category or some other arbitrary property.
You need to make sure you mark tiles on your tilemap as occupied by the objects you place there.
You can do this using the occupyTile method of the entity you place.

Code: Select all
tree = new TreeEntity()
    .mount(tileMap)
    .translateToTile(x,y,0) 

// calling the following will occupy 1 square where the object is based on it's translation
// this occupyTile method takes are number of arguments, checkout the source code in IgeEntity for more info

tree.occupyTile()

// you can make an object occupy as many tiles as you like so if you have a building that covers a 2x2 square it's as simple as:
building.occupyTile(x,y,2,2);


So now you have entities mounted and occupying spaces on the tileMap

Now you need to implement the tileChecker callback for the player and for the weapons that move too.
You can do this in a generic way or specific to the player,weapon, it's up to you.

here's an example for your player:
Code: Select all
_entityTileChecker: (tileData, tileX, tileY) ->
      if(tileData) {
         //there's something there, block pathing
         return false;
      }
      return true;
}

// bind this callback to the player's pathing
player.path.tileChecker(player._entityTileChecker)


here's how it might look for your weapons that can pass through some objects
Code: Select all
_entityTileChecker: (tileData, tileX, tileY) ->
      if(!tileData) {
         //nothing there, allow pathing
         return true;
      }

      // if you're using inheritance like I suggest above you can do the following:
      if ((tileData instanceof RockEntity) || (tileData.instanceof RiverEntity)) {
         return true;
      }

      // or if you have added objects that can be passed through to a special category
      // say 'passableobjects' then you can check like so:
      if(tileData.category() == 'passableobjects') {
         return true;
      }

      // anything else is impassable.
      return false;
}

// bind this callback to the projectile pathing
projectile.path.tileChecker(projectile._entityTileChecker)


I think that should do what you need.
You can write whatever code you like in the tileChecker callback, just be aware that that callback is run against every tile of a potential path during the path generation, simple checks like i've done above will have little to no noticeable effect on performance.
I don't work for Irrelon. All comments are my own.
I would strongly encourage anyone building production projects with Isogenic to buy a premium licence, it costs very little and will help towards continued development of the engine. Irrelon have spent thousands of hours developing this wonderful platform with many features found in AAA game engine.
User avatar
robaldred
 
Posts: 243
Joined: Wed Oct 23, 2013 8:09 pm
Location: Manchester, England

Re: Object layer and isometric map

Postby Killersan » Mon Mar 02, 2015 6:22 pm

Rob. I don't want to to search the path for the missiles I just want to tween them through the direct line between two objects and before I'll start to tween i would like to check if the tiles on which the direct line cross are occupied by the lower objects like water and small rock or by higher objects like tree or house.
In first case the missile should pass through the tile, even it's occupied, in second case the missile should not fire at all with some kind of message on screen "target is not visible" or something like that.
User avatar
Killersan
 
Posts: 24
Joined: Sat Jun 21, 2014 1:45 pm

Re: Object layer and isometric map

Postby robaldred » Mon Mar 02, 2015 10:06 pm

That's going to be very difficult without a physics engine.
The ideal approach would be to raycast/raytrace from the players position to the targets position and see what it hits on the way.
If you are using Box2d you can shoot a dynamic body towards a targets and setup collision filtering.

If not, you're going to have to write something yourself, use trig to plot the magnitude of the vector between your player and target, and work out the tiles on the route in line of sight as an array. Then before you fire you can check if they're occupied by just looping over the tiles array, until you reach something impassable or your target.

This is more of a general maths/game dev question and not related to the game engine.
I'd recommend posting on http://gamedev.stackexchange.com/

You might get some decent replies over there.
I'd be interested to hear how you get on, so please drop a message back here if you find a solution.
I don't work for Irrelon. All comments are my own.
I would strongly encourage anyone building production projects with Isogenic to buy a premium licence, it costs very little and will help towards continued development of the engine. Irrelon have spent thousands of hours developing this wonderful platform with many features found in AAA game engine.
User avatar
robaldred
 
Posts: 243
Joined: Wed Oct 23, 2013 8:09 pm
Location: Manchester, England

Re: Object layer and isometric map

Postby Killersan » Tue Mar 03, 2015 11:13 pm

As usual, thx Rob for Your input.

I thought at start about something simple like putting vector between player and target, then check which tiles are occupied on the vector's path (not IGE Path) and then if all tiles are passable (like grass, dirt, ice, desert even with small objects like water, rocks, etc) then animate the cast / shot or if not then put the message on the screen that target is not visible or tween the cast / shot between player and occupied tile with which should collide (where the blast animation should appear at the end).

I have to admit that at start I was trying to use Box2d and it worked well, but I wasn't able to use Pathfinding with it and I had some troubles to use mouse to move the player (which I would like to keep). I think with Box2d it would be better to move my player through WSAD keys for example.
It was extremely hard to put exact force to player by clicking the mouse on the point where the player should move to with constant speed. Thats why I changed approach and turned off physics and now I'm trying to emulate some functionalities similar to those in physics :)

After I'll finish I'll put some showcast here to provide You info how it works.
User avatar
Killersan
 
Posts: 24
Joined: Sat Jun 21, 2014 1:45 pm

Re: Object layer and isometric map

Postby robaldred » Mon Mar 09, 2015 2:00 pm

Yeh your Line Of Sight vector idea is the right approach.
If one of the tiles is blocking then you could work out the distance along the vector animate to that point and then destroy the projectile before it reaches it's target.

This is where ray tracing/casting would come in very handy, however without a physics engine you don't have that luxury.

Looking forward to seeing your results.
I don't work for Irrelon. All comments are my own.
I would strongly encourage anyone building production projects with Isogenic to buy a premium licence, it costs very little and will help towards continued development of the engine. Irrelon have spent thousands of hours developing this wonderful platform with many features found in AAA game engine.
User avatar
robaldred
 
Posts: 243
Joined: Wed Oct 23, 2013 8:09 pm
Location: Manchester, England


Return to Help & Questions

Who is online

Users browsing this forum: No registered users and 1 guest
cron