Page 1 of 1

Help regarding Entities (NPc, Enemies) turn based movement

Posted: Wed Apr 17, 2024 3:47 pm
by niokasgami
Hi,
I want to say I absolutely love the grid controller assets its simplify everything when its come to implement the system.

I was although unsure how to approach the movement for the enemies and npc to be also turn based.

if I am wrong and its not the proper forum I apologize.

How would I approach to create the enemies to be turn based (aka only when you move)?

Re: Help regarding Entities (NPc, Enemies) turn based movement

Posted: Wed Apr 17, 2024 4:48 pm
by Tony Li
Hi,

Thanks for using Grid Controller!

I recommend having a "game manager" or "turn manager" script that manages turns. When you process a turn, call GridController.Instance.ProcessTurn() to process the player's movement and also call whatever code you need to move enemies and NPCs.

You might be interested in using Aron Granberg's A* Pathfinding Project. (It's 50% off right now in the Spring Sale.) It can handle grid-based movement for enemies. See also A* Pathfinding Project's Utilities for turn-based games documentation.

Re: Help regarding Entities (NPc, Enemies) turn based movement

Posted: Wed Apr 17, 2024 5:23 pm
by niokasgami
Hi thank you!

I though I assume the movement would be similar to how you do the movemen with grid controller. Although, as I appreciate the offers of the A* plugin I sadly dont have the funds for it so ill try to do my own approach for it.


of what I understand everytime I move right it will trigger process turn or I gotta push it myself?

Re: Help regarding Entities (NPc, Enemies) turn based movement

Posted: Wed Apr 17, 2024 8:54 pm
by Tony Li
Hi,
niokasgami wrote: Wed Apr 17, 2024 5:23 pmI though I assume the movement would be similar to how you do the movement with grid controller.
Yes, but simpler in a way since your code controls the AI instead of movement being at the whim of the player. It really depends on your game. In Wizardry, for example, the player just moves and encounters randomly pop up. There's no need for any kind of movement. Many dungeon crawlers use very simple movement logic: if the player is nearby, the enemy will turn to face the player. Then it will move forward one square each turn until it's next to the player. That produces very decent behavior without the need for any pathfinding. If you do need something more complex, there are many tutorials (here's one) on how to pathfind on a grid.
niokasgami wrote: Wed Apr 17, 2024 5:23 pmof what I understand everytime I move right it will trigger process turn or I gotta push it myself?
It's the opposite. When your game is ready to process a turn (e.g., let player move, let NPCs move, etc.), call GridController.Instance.ProcessTurn() to push it.