- Home /
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.
Answer by MaxGuernseyIII · Sep 30, 2017 at 03:35 AM
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.
Thanks $$anonymous$$ax, this worked great! (and I'm definitely not trying that coroutine haha)
Your answer
![](https://koobas.hobune.stream/wayback/20220612135945im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make a Grid movement (tile per tile) 1 Answer
help with a player moving in a grid with obstacles 2d 0 Answers
Multiple Cars not working 1 Answer
Moving An Object Slowly and Indefinitely? [C#] 1 Answer
Distribute terrain in zones 3 Answers