I was wanting to know if was any way I could check to see how many grid cells one object is away from another. I just have a very basic grid, that I have each cell set to 32x32. I have the player at once position in the grid, and was wanting to store the number of cells that are inbetween the player and the mouse, inside a variable. I've been trying for the past hour, but I can't seem to figure it out. Any help would be greatly appreciated.
You can focus on just the x and y direction independently then sum the results. For example, if player is in [2,7] and mouse is [6,1] The x change is 6-2=4. The y change is 1-7 = -6. By taking absolute values of both x and y changes, total grid moves to get from player to mouse is 4+6=10.
script grid_distance: takes x1,y1 of first cell, and x2, y2 of second cell. Code: var x1 = argument0; var y1 = argument1; var x2 = argument2; var y2 = argument3; return abs(x1- x2) + abs(y1 - y2);
point_distance(grid_x1,grid_y1,grid_x2,grid_y2) will also do the exact same thing. There's not really a reason to write your own function when this exists, unless you're looking to extend functionality in some way.
I believe the OP wants a number of grid moves, not a radial distance in grid spaces. But either way he has the answer now.
That can return fractional values. You don't want fractions with grid distances. If you are at cell 0,0 trying to get to 2,3 that's a distance of 5 cells. Your suggestion would return 3.6 cells.
@Relic @TheouAegis Ah, ok, I was assuming it calculated using the manhattan distance, but obviously not.