How to move player on over-world map. C#

Hey everyone,

I need help with writing a script to move my character along the ‘tiles’ of my 2d map. I thought perhaps, when ‘A’ is pressed, I just change the coordinates a set amount (like, xcoord += 5;) or something, but I’m not sure if that’s the right way to do it, or how to access the coordinates in the script.

Any help is appreciated, thank you.

There are multiple ways to handle it. If your tiles are individual game objects, you can get their world coordinates and set your character’s world coordinates with Transform.position. You can affect direction with Transform.rotation. You can set both of those at once with Transform.SetPositionAndRotation or you can use an animation to make your character look like it’s walking.

If your tile map is a single game object, you must have a way of (at least) finding its local coordinates. You can map its local coordinates into world coordinates with Transform.TransformPoint or Transform.TransformVector, depending on what kind of coordinates you are transforming.

You can also do other things, like make your player smoothly pointing at something or gradually modifying its position over time using a coroutine but, that’s like writing your own custom animation engine. So I shy away from that stuff.