G
GrkGmMkr
Guest
Hello all,
I am trying to figure out a way to create a situation where within a grid I can right click onto a square and the object will snap to the nearest set gridpoint.
Something along the lines of chess but the game isn't set up from the get go. The player must set the pieces up on the gameboard by left clicking on the piece and putting it in the correct spot.
Currently I am able to select the object and place but it is only going to my mouse_x and mouse_y position. I also have a grid system created by making a script that, in essence, has variables that equal a number.
Such as:
if (x==5) {gx=1;}
else if (x==5+5*1) {gx=2;}
else {gx=0;} //states that it isn't on the grid and not a legal spot
and
if (y==5) {gy=1;}
else if (y==5+5*1) {gy=2;}
else {gy=0;} //states that it isn't on the grid and not a legal spot
so if i right click and my mouse_x = 7 && mouse_y = 6 then the object will snap to x=5 && y=5
Any help would be appreciated. If there is a better system to create a coordinate situation like the game Battleship, such B1 or C10 etc etc, please do let me know. Im sure there is but i am unfamiliar with the way it is done.
What confuses me is that i would assume the above code does exactly what i want (the battleship gameboard) but it doesn't like to a global variable. When i replace the number go global variable, like so;
gx=1
to
gx=global.x1
it doesn't recognize the code anymore.
I hope that makes sense
I am trying to figure out a way to create a situation where within a grid I can right click onto a square and the object will snap to the nearest set gridpoint.
Something along the lines of chess but the game isn't set up from the get go. The player must set the pieces up on the gameboard by left clicking on the piece and putting it in the correct spot.
Currently I am able to select the object and place but it is only going to my mouse_x and mouse_y position. I also have a grid system created by making a script that, in essence, has variables that equal a number.
Such as:
if (x==5) {gx=1;}
else if (x==5+5*1) {gx=2;}
else {gx=0;} //states that it isn't on the grid and not a legal spot
and
if (y==5) {gy=1;}
else if (y==5+5*1) {gy=2;}
else {gy=0;} //states that it isn't on the grid and not a legal spot
so if i right click and my mouse_x = 7 && mouse_y = 6 then the object will snap to x=5 && y=5
Any help would be appreciated. If there is a better system to create a coordinate situation like the game Battleship, such B1 or C10 etc etc, please do let me know. Im sure there is but i am unfamiliar with the way it is done.
What confuses me is that i would assume the above code does exactly what i want (the battleship gameboard) but it doesn't like to a global variable. When i replace the number go global variable, like so;
gx=1
to
gx=global.x1
it doesn't recognize the code anymore.
I hope that makes sense