(Brackeys Top Down Movement Tutorial), and I was wondering, how would you make your character move tile by tile, so if you tap the “W” key once, it moves one tile, and if you hold down the “W” key, you move smoothly across tiles until you let go, which stops you in the middle of one tile again. Anyone know? I tried searching it up, but no avail.
Thanks!
Search here or google for tile (or grid) based movement, and tile (or grid) smooth movement. You’ll find several discussions.
It is very common technique. You can find it in Unity’s tutorials; See 2D Roguelike tutorial series.
Basically decide the axis based on player input (L/R/U/D) then based on this, get the next closest tile center and move there.
Smooth movement only requires little more work - after getting input, do lerp / smoothdamp with Vector3 to move to target position. When target is reached, allow input again.
Determine the length of time it takes to move to the tile. Use IEnumerator to move the char to that tile. maybe MoveLeft takes longer than move right? You would need to customize each direction NOT unlike moving up,down, left, or right. You’re only doing so for a certain allotted amount of time.
So why not watch Unity’s tutorial, where it is explained?
“So is there no simple way to just make the movement in steps?”
And what is a simple way? If you are somewhat familiar with the concepts and unity/C# commands needed you can create this yourself - otherwise someone else will have to give you the code…
Anyway I think I pretty much explained the steps that are needed;
Decide the axis of movement / direction based on player input (left / right / up / down) .
Get the next closest tile center/position based on input (depending on your character pivot).
Set some state variable so you know not to take input while moving (unless you do this by design).
Move to target by using lerp / smoothdamp on your transform.
When target is reached, allow input again.
If you are not familiar with the steps needed to do this, then you probably want to watch how it can be done?
I don’t know how that relates to your original question “how would you make your character move tile by tile” - adding some automatic movement to tile based movement is another question.…
If you just need a pause after each tile to tile move, add a timer with counter, increment it until some defined time is passed, then allow input again. Or use coroutines instead of running your code in Update.