Grid movement


#1

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.


#2

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.


#3

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

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


#5

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