Page 1 of 1

Snap to grid help.

PostPosted: Fri Jul 02, 2010 9:27 am
by NevenResnik
Hey!

EDITED:
I have a problem with my GAMEPlay. I don't mean the following in terms when editing the game, but in Game Mode, while it is running. I was wandering if there was a way to make characters snap to a grid when moved over it with a mouse. The Character would follow the mouse, off course. I just don't know how to make it snap to a square grid when moved over it (it's a grid field, like a big square, it would include many of them.)

Re: Snap to grid help.

PostPosted: Fri Jul 02, 2010 10:41 am
by Bee-Ant
Press "Shift"...

Re: Snap to grid help.

PostPosted: Fri Jul 02, 2010 11:25 am
by NevenResnik
Oops! There seems to be a misunderstanding. What I meant was, in the GAMEPLAY itself. I set the actor with the "Follow Mouse" rule. And when I hover my mouse above the grid it snaps to each field. Have you played Plants versus Zombies, or any other Tower Defense game? When you place the towers, they can be placed only in specific square fields, not anywhere on the map. I'm sorry for not being clear. I need the actor to snap to the grid (Which I will draw) in the gameplay while the game is running.

Re: Snap to grid help.

PostPosted: Fri Jul 02, 2010 12:04 pm
by Bee-Ant
Try this on DrawActor:
Code: Select all
int xx,yy;
int grid=40;

xx=(xmouse+view.x)/grid;
yy=(ymouse+view.y)/grid;

if(drag==1)
{
    x=xx*grid;
    y=yy*grid;
}

I use this code to drag the object snappy...