Grid movement

Hello all,

How would I limit a player’s movement to only be able to jump between squares on a grid. If you have played or seen crypt of the necromancer then that’s what I’m going for.

Hi! What have you tried this far? What do you know this far? Do you know how to make a character move from player input? Do you know about tiles? With those two, you should be able to get quite far, so check those out of you haven’t already.

1 Like

Some thoughts:

  • Instead of allowing free movement in a per pixel or fractional pixel space you need to think of a grid and limit when the player is allowed to move
  • Decide on a grid size, very likely the same as your tiles. Let’s store this in variable GRID_SIZE
  • Keep track of player position in grid. You could base this on the player game object position but I’d suggest keeping track in a separate x and y variable. Use a vector3. self.grid_pos = vmath.vector3()
  • Enable and accept input when player is in idle state.
  • On input:
    • Check if player is allowed to move in direction.
    • Update grid x and y position immediately.
    • Disable input.
    • Use go.animate to move to new position. go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, self.grid_pos * GRID_SIZE, go.EASING_LINEAR, 1, 0, cb)
    • Use go.animate finished callback to enable input.
4 Likes

Hello and thanks for your reply!

Sorry for not replying at an earlier date. I have not been able to use Defold as much recently, and as a result I have put the project on hold for the time being. I have also decided to get a better grasp of lua and Defold overall. I will return to this post at some point.

Thanks,

Alola

1 Like

Hello,

Thanks for your input once again and sorry for not replying at an earlier date. I am taking a step back and really getting to learn the very basics of Defold and lua to help me better myself overall. I will return to this post at a later date.

Thanks,

Alola

1 Like

Thank you for this explanation, I’m thinking of implementing such a thing for some games. Sorry for the necromancy, there seems to be a lot of great answers to questions on this forum which were asked well before I knew about Defold.

2 Likes

There is an asset for this: https://defold.com/assets/defoldgridengine/

3 Likes

Hello @WhiteBoxDev,

As far as I can tell that library assumes that the grid is a grid of boxes, can’t be rectangles? Is that accurate? Basically, I think it would be good to have the option to have a different dge.stride_x and dge.stride_y.

Cheers for the awesome library.
Spen

Yes, that’s correct.

It depends if that would be useful to people. All of the games I can think of that use a grid system use squares and hexagons. If rectangles were requested (on GitHub) then I would look into it.

1 Like

Understandable. I’m currently looking at the property map, which is a great feature to add to the grid based movement, and can allow for hidden information which is also very cool. However, I don’t understand how one would convey 11,1 vs 1,11 on the property map?

2 Likes

Wow, that’s interesting. The problem has never come up before surprisingly. Yep, that’s an issue I did not foresee. Thanks for asking about that. I’ll make sure to solve the problem tonight and push an update.

2 Likes