GRID-MOVEMENT-SYSTEM (GMS)
By RUCCUS
The system auto-moves an object with the mouse. There have been other ways of doing this but I THINK this is the simplest and most efficient. I designed it to work with my game creator Im working on, it could be used for maybe a map maker or a game that involves moving the user with the mouse on the screen.
The main delema that newcomers face when trying to do this is that the two grids - the screen grid and the 3d area grid - are very different. For instance 0,0 on the screen is in the top left where as 0,0 in the 3d area is in the center of the world.
Here's the simple formula/code, just put it in the beginning of the loop and it should work. Replace the object number with the object you wish to move. I should have a code base entry up soon for it.
IF MOUSEY()<237 THEN POSITION OBJECT 1,MOUSEX()-(SCREEN WIDTH()/2),0,ABS(MOUSEY()-(SCREEN HEIGHT()/2))
IF MOUSEY()>237 THEN POSITION OBJECT 1,MOUSEX()-(SCREEN WIDTH()/2),0,-(MOUSEY()-(SCREEN HEIGHT()/2))
!NOTE!
The system works best if you position the camera's y coordinate at around 435, then just point the camera to 0,0,0 and all should work. Also, I'm using a box with a 30x30x30 size, the bigger the object the farther you have to zoom out or higher you have to position the camera, the smaller the object the lower you have to position the camera. I might be able to come up with another formula to find out the position for the camera according to the size of the object.
Quote: "!NOTE 2!
The system may not work for all screens, I have an average sized monitor screen so it should work for most people but if your screen is small or large it may not work. Im coming up with a formula to calculate the screen width and customize the system accordingly.
My screen is 640x475"
-Fixed.
-Breakdown-
Basically, the code subtracts the mouse position from the object's position, and then positions the object accordingly to this outcome. If the mouse is above the halfway point of the screen it moves the object up with the mouse using ABS to make the answer positive, and if the mouse is in the lower half of the screen it moves the object down using the - symbol to make the answer negative.
I dont think I explained it too clearly but...hey it works
-Plans-
I should have the advanced demo up soon, this is only a simple version. Ill be adding the following to the next version:
- Snap to grid allignment (Eg. the object moves every 10 units)
- Click grab/drop placement.
- A function to move the camera left, right, up or down if the mouse hit's the edge of the screen.
c/c appretiated.
- RUCCUS