- Home /
Having a player object move on coordinates
Since a few weeks I have been working on a simple tile based puzzle game in unity, I wanted to ask if someone on here might know how to help me out with a problem we have. The game needs to have a player that can jump from tile to tile so I think we need to put movement trough coordinates since we only want it to be able to jump one tile each time. The meaning of the game is to put all tiles in a certain pattern to clear the level, I hope someone can help out with this problem.
Answer by Jesse Anders · Oct 12, 2010 at 10:59 AM
Presumably you have the positions of all the tiles available (e.g. stored in a 2-d array). At any one time, the player is associated with one of the tiles, which specifies the player's current position. In response to input events (buttons/keypresses/etc.), the player can jump to a neighboring tile. The indices of the new tile can easily be determined from the indices of the current tile; once new tile indices have been assigned to the player, the player's new position can be determined as well.
Functionally, a good place to start might be (if you haven't done this already) simply to move the player instantaneously from one tile to another. The rest is really just polish; that said, it's probably the polish that will take the majority of the time.
The first thing you can do to smooth things out a bit is to interpolate to the new position over a short period of time rather than just 'teleporting' instantly. Eventually you'll likely also want to play some sort of 'jumping' animation. And so on.
Does that help at all? Or is there something more specific that you're looking for?
This does describe what I am looking you yes, the problem is my scripting issn't really that good, so to tell the truth I have no idea how to start working on what you just explained. If you have the time to look into it that would be great, but even if you don't you already gave me some good info and I am grateful for that.
Thanks
I'd start with the simplest implementation possible; that is, 'teleporting' the player instantly from tile to tile. Take a look at Input.GetButtonDown(), Get$$anonymous$$eyDown(), and/or GetAxis() for movement. For setting the player's position, look at Transform.position. You'll also most likely want a 2-d array (in one form or another) that stores the tiles and/or tile positions. If you run into problems from there, I'd recommend posting whatever code you have in a new thread along with your questions. (Note that for those sorts of questions, you might have better luck in the forums.) Hope that helps :)
Your answer
Follow this Question
Related Questions
Water Flowing in pipes 0 Answers
Cube Rotating & Moving 1 Answer
Puzzle logic stuck 2 Answers
Moving object on plane 1 Answer
tilemap tiles broken 0 Answers