I'm using an isometric tilemap(2:1) and I can't figure out how to make grid based movement on it's surface. I managed to get a code working for the grid based movement, moving my character with 0.5 along the Y axis and 0.86 ( sqrt(3)/2 ) along the X axis since I imagine it should work as if they are diamonds with the side of 1 unit, but it doesn't align with the center of the next tile. Here is my movement code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Assertions.Must; public class Movement : MonoBehaviour { Vector3 pos; // For movement float speed = 5f; // Speed of movement public float x = 0.86f; public float y = 0.5f; void Start() { pos = transform.position; // Take the initial position } void FixedUpdate() { if (Input.GetKey(KeyCode.A) && transform.position == pos) { // Left //pos += Vector3.left; pos += new Vector3(-0.86f, 0.5f, 0); } if (Input.GetKey(KeyCode.D) && transform.position == pos) { // Right //pos += Vector3.right; pos += new Vector3(0.86f, -0.5f, 0); // miscare in diagonala } if (Input.GetKey(KeyCode.W) && transform.position == pos) { // Up //pos += Vector3.up; pos += new Vector3(0.86f, 0.5f, 0); } if (Input.GetKey(KeyCode.S) && transform.position == pos) { // Down //pos += Vector3.down; pos += new Vector3(-0.86f, -0.5f, 0); } transform.position = Vector3.MoveTowards(transform.position, pos, Time.fixedDeltaTime * speed); // Move there } 


