The movement of heroes on the grid.

Blockquote
I want to make sure that enemy and allied characters are on the same grid. But the main thing is that each character has cells on which he could walk. That is, so that, for example, the character “X” could walk only 3 squares around himself. And the character “Y” is 6 cells around him. Does anyone know how this can be done? I will be grateful for the answer.

hi @WolfiBand

This could be a very detailed answer, so the best way is to create yourself a flow chart of rules for each character.

  1. Start with some sort of array to hold the grid positions and their content.

  2. Then do a check on the current player what his rules of movement are. maybe some sort of pre-set values assigned to your character.

  3. check where the player (you) or (AI) wants to move based on his allowed rules, then check if the space is occupied, if it is then make the ai or player change their option, or just disallow them completely from that option. Otherwise move the player/ai. Or if they are allowed to occupy the same space does that mean they fight? if they fail they return to previous place, or win the enemy either dies or retreats?

It is a very vague question and could be accomplished in many ways.
Start simple with the grid system, then figure how to assign rules just using simple maths by direction, and distance.

Asking for someone to make it for you would defeat the learning process and you may not understand how it works neither.

Have a go, you will be surprised what you can accomplish and by all means ask when you get stuck on a particular routine.

Stewart

Edit: You could make each individual cell an blueprint if the arena is small, which would mean each cell has its own code inside too which maybe advantagious or not. But no good for a large area.

I have a large map, I wanted to find out exactly how to create such a grid, because most of the guides I saw were not at all about the grid that I needed. But thanks for the answer.

Ok so a simple math calculation that finds the lower bounds of the grid you’re standing in.

i.e. if a grid was 100 units square, and it was a 3x3 grid (yes tiny just an example). and you was stood at 220,110. You know your grids are 100x100 so find the lower limit of each number to the nearest grid line.

So the lower limits are (220 ÷ 100) and (110 ÷ 100) both rounded (down) .
this will give you an integer for each grid location, obviously account for 0 , so easiest way is to start your grid at 0,0 otherwise just add 1 the each location if you wish 1,1 as the first location.

The above will give you integer grid coords then if you have an array that holds any information about each coord.

In reverse you could do a math calculation on the grid location if say you select grid location 3,10 and you want your player to stand in the centre, just add 0.5 to each grid location and times by 100 for real world location centred in the grid chosen.

Also if this is required to be a visual grid you will need to create some sort of overlay texture on your landscape (or the actor/primitive that you are standing on) just make sure it aligns to your grid size and starting location.

Hope this wasn’t too confusing.
always sounds better in your head!

Stewart

Ok, thanks.

No problem, think it out on paper what u need, then create a flow chart of sorts of each step, then break them down into small parts and code it step by step.