Moving to the mouse
Moving to the mouse
Is there any way I could get a pawn to follow the mouse cursor?
Over 3 years (has it been that long?) and just now I noticed the day and month of my birthday were switched. Whoops!
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Re: Moving to the mouse
Do you mean point and click movement like Diablo or Dungeon Siege?
Many Bothans died to bring you this signature....
Re: Moving to the mouse
Yes, exactly like in those games.
Over 3 years (has it been that long?) and just now I noticed the day and month of my birthday were switched. Whoops!
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Re: Moving to the mouse
I'm not sure that RF can do this. QoD???
Many Bothans died to bring you this signature....
Re: Moving to the mouse
I know that RF can have the cursor changed so that it's not fixed to the center, lemme find the topic...
Hmm, best I can find is SCURF: viewtopic.php?f=11&t=2071 but i'm sure there was a better topic about RTS games.
Hmm, best I can find is SCURF: viewtopic.php?f=11&t=2071 but i'm sure there was a better topic about RTS games.
Once I was sad, and I stopped being sad and was awesome instead.
True story.
True story.
Re: Moving to the mouse
All well, if all else fails I can learn blender and Unity 3d.
*edit*
On second thought, I could go the route of Halo Wars, with the use of a crosshair in the center of the screenie to select troups.
*edit*
On second thought, I could go the route of Halo Wars, with the use of a crosshair in the center of the screenie to select troups.
Over 3 years (has it been that long?) and just now I noticed the day and month of my birthday were switched. Whoops!
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Re: Moving to the mouse
Don't worry, it's possible. Just wait for someone who knows how to post.
Once I was sad, and I stopped being sad and was awesome instead.
True story.
True story.
Re: Moving to the mouse
Over 3 years (has it been that long?) and just now I noticed the day and month of my birthday were switched. Whoops!
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Re: Moving to the mouse
There are (at least) two ways to do this. In theory it may sound simple, but actually it's pretty complicated to implement. Both methods require a pawn positioned at the camera:
1.) Shoot a pawn from the camera to the spot where the mouse is pointing. When the pawn collides with a wall, that's the spot where the mouse was clicked and you can easily get its coordinates from the pawn's coordinates.
2.) Use the pawn at the camera to measure the distance to the point where the mouse was clicked (GetCollideDistance), and then calculate the coordinates of that point.
And then the challenging part: you have to find a way to transform the 2D-coordinates of the mouse (X,Y) to an angle (yaw, pitch). For example, if the mouse is at (100,200) and you click, you have to somehow figure out which direction the "projectile pawn" should be launched at (or where exactly you should aim the GetCollideDistance method). Needless to say, this all involves a lot of trigonometry.
You're gonna have to find out how the field of view system works in RF. AFAIK, the default camera FOV is 2. That is in radians, I believe. So that would mean the angle between a line that goes straight through the center of the screen and a point near the edge of the screen would be 1 radian (the angle between two points at the opposite sides of the screen is 2).
I know this is a very shallow and unclear explanation, but it's the best I can do. If you still wanna give it a shot, I can try to draw a picture to demonstrate.
1.) Shoot a pawn from the camera to the spot where the mouse is pointing. When the pawn collides with a wall, that's the spot where the mouse was clicked and you can easily get its coordinates from the pawn's coordinates.
2.) Use the pawn at the camera to measure the distance to the point where the mouse was clicked (GetCollideDistance), and then calculate the coordinates of that point.
And then the challenging part: you have to find a way to transform the 2D-coordinates of the mouse (X,Y) to an angle (yaw, pitch). For example, if the mouse is at (100,200) and you click, you have to somehow figure out which direction the "projectile pawn" should be launched at (or where exactly you should aim the GetCollideDistance method). Needless to say, this all involves a lot of trigonometry.
You're gonna have to find out how the field of view system works in RF. AFAIK, the default camera FOV is 2. That is in radians, I believe. So that would mean the angle between a line that goes straight through the center of the screen and a point near the edge of the screen would be 1 radian (the angle between two points at the opposite sides of the screen is 2).
I know this is a very shallow and unclear explanation, but it's the best I can do. If you still wanna give it a shot, I can try to draw a picture to demonstrate.
Pain is only psychological.
Re: Moving to the mouse
I have never wrote a script for RF but after looking at the script functions it looks like you can use the GetMousePosX() and GetMousePosY() functions to get the position of the cursor. It also looks like you can use the CheckArea() function to see if the pawn is close to the cursor. And you can probably use the Points and Orders functions such as SetTargetPoint() to set a target for the pawn and use the MoveToTarget() function to move the pawn to the target.
Re: Moving to the mouse
Ok, I don't have the right terminology, but I think that the general idea is there (time to look at the RF manual):
(Mouse position is arranged so it is relative to the center)
Angle 1 = (((180/pi)*1)/((screen_resolution_x/2)/mouse_x+0.001)))
Angle 2 = (((180/pi)*0.75)/((screen_resolution_y/2)/mouse_y+0.001)))
About the numbers
180/pi - convert from radians to degrees
1 - screen is 2 radians "wide", so half is 1
0.75 - the screen 1.5 radians "tall", so half is 0.75 (correct me if I'm wrong)
2 - divide the screen in half
0.001 - make sure that the angle rational, as one cannot divide by 0
I'm going to slash out the script tonight (hopefully), where a projectile (using the built in system) will fire from the camera, towards the mouse, but move through 3d space.
(Mouse position is arranged so it is relative to the center)
Angle 1 = (((180/pi)*1)/((screen_resolution_x/2)/mouse_x+0.001)))
Angle 2 = (((180/pi)*0.75)/((screen_resolution_y/2)/mouse_y+0.001)))
About the numbers
180/pi - convert from radians to degrees
1 - screen is 2 radians "wide", so half is 1
0.75 - the screen 1.5 radians "tall", so half is 0.75 (correct me if I'm wrong)
2 - divide the screen in half
0.001 - make sure that the angle rational, as one cannot divide by 0
I'm going to slash out the script tonight (hopefully), where a projectile (using the built in system) will fire from the camera, towards the mouse, but move through 3d space.
Over 3 years (has it been that long?) and just now I noticed the day and month of my birthday were switched. Whoops!
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Some 2d games I made, haven't made anything in a year though O.o
http://www.yoyogames.com/users/GMer56
Re: Moving to the mouse
Here is code to detect collision with the floor of the world and get you the exact point in world space. Camera should be rotated 45 degrees on the X and Y axis. The ceiling needs to be defined as sky for the ray collision to work. You don't need a skybox texture.
Code: Select all
POINT MousePos;
GetCursorPos(&MousePos);
GE_Collision MouseRayCollision;
geVec3d dir;
geVec3d start, end;
start = CameraBaseForm.Translation;
geCamera_ScreenPointToWorld (PrimaryCamera, MousePos.x, MousePos.y, &dir);
geVec3d_AddScaled (&start, &dir, 10000.0f, &end);
BOOL Result = geWorld_Collision (CurrentLevel, NULL, NULL, &start, &end, GE_CONTENTS_CANNOT_OCCUPY, GE_COLLIDE_ALL, 0xffffffff, NULL, NULL, &MouseRayCollision);
Many Bothans died to bring you this signature....