playMaker

Author Topic: Grid-based movement & centering the player on tiles  (Read 4546 times)

marcos

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 199
Grid-based movement & centering the player on tiles
« on: May 17, 2011, 10:52:47 AM »
Hello everyone,
I'm working on a grid based movement system for a game.
Currently I'm using iTween actions (moveBy) to move the character left,right, forward and back. This may become a problem later on as I wish to have pushable blocks, but we'll cross that bridge when we reach it.

I currently have two problems that I'm a bit stumped by:

a) using the iTween actions seems to ignore colliders, so tiles that are raised up as walls do absolutely nothing to stop the player from moving inside of them.
b) due to the 3d nature of the game, and level designs, it is possible for the character to step off of the platforms (which is intended) and land on another tile off-center (which is not intended). Ideally the player should always sit in the center of the tile that it is standing on.

So I guess in a roundabout way I'm asking what would be the best system for this sort of 3d grid-based movement, or how I could specifically address these two problems.

I haven't the foggiest idea how to tackle a). I thought maybe of having 4 colliders on each polar direction, and if a collider was overlapping a wall disallowing movement in that direction.
For b) I was thinking about raycasting below the player after an event that would set the character off-center, testing for the platform below the player, comparing the X/Z of the player and the platform and then transitioning the player to the platform's X/Z.

Any help would be much appreciated, I shall keep trial and erroring in the meantime.
Thanks in advance.

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Grid-based movement & centering the player on tiles
« Reply #1 on: May 20, 2011, 04:55:27 AM »
Hi,
Haven't got an exact answer for you but for question b.) what about simply getting the width of any horizontal tile you collide with and the halving it? That'd give you it's center... assuming your tiles are square of course. If they're not you'll have to get it's width in two directions and halve both.
It's a bit like the scripts you see for getting the screen width and height. Plenty of those over on Unity Answers.
« Last Edit: May 20, 2011, 05:00:01 AM by Duffdaddy »

acott

  • Guest
Re: Grid-based movement & centering the player on tiles
« Reply #2 on: February 04, 2013, 06:41:05 PM »
Hey, Sorry to dig up an old thread but I would love to know how you got your character movement working based on the grid system? I have been searching for quite some time now and cant come up with a solution as to how I can get my character to move from block to block in one touch of a key all while staying centered!

Any help would be greatly appreciated