Moving to the mouse

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
GMer
Posts: 329
Joined: Thu Oct 25, 2007 4:49 pm
Location: On the rock in the 3rd solar orbit.

Moving to the mouse

Post by GMer » Sun Feb 14, 2010 5:46 am

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

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Re: Moving to the mouse

Post by paradoxnj » Mon Feb 15, 2010 2:12 am

Do you mean point and click movement like Diablo or Dungeon Siege?
Many Bothans died to bring you this signature....

User avatar
GMer
Posts: 329
Joined: Thu Oct 25, 2007 4:49 pm
Location: On the rock in the 3rd solar orbit.

Re: Moving to the mouse

Post by GMer » Mon Feb 15, 2010 3:43 am

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

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Re: Moving to the mouse

Post by paradoxnj » Tue Feb 16, 2010 8:12 pm

I'm not sure that RF can do this. QoD???
Many Bothans died to bring you this signature....

User avatar
zany_001
Posts: 1047
Joined: Fri Mar 02, 2007 8:36 am
Location: Aotearoa

Re: Moving to the mouse

Post by zany_001 » Tue Feb 16, 2010 8:17 pm

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.
Once I was sad, and I stopped being sad and was awesome instead.
True story.

User avatar
GMer
Posts: 329
Joined: Thu Oct 25, 2007 4:49 pm
Location: On the rock in the 3rd solar orbit.

Re: Moving to the mouse

Post by GMer » Tue Feb 16, 2010 10:56 pm

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.
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

User avatar
zany_001
Posts: 1047
Joined: Fri Mar 02, 2007 8:36 am
Location: Aotearoa

Re: Moving to the mouse

Post by zany_001 » Wed Feb 17, 2010 12:24 am

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.

User avatar
GMer
Posts: 329
Joined: Thu Oct 25, 2007 4:49 pm
Location: On the rock in the 3rd solar orbit.

Re: Moving to the mouse

Post by GMer » Wed Feb 17, 2010 12:34 am

:D
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

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Moving to the mouse

Post by Juutis » Wed Feb 17, 2010 10:31 pm

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.
Pain is only psychological.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Moving to the mouse

Post by Allanon » Wed Feb 17, 2010 10:33 pm

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.

User avatar
GMer
Posts: 329
Joined: Thu Oct 25, 2007 4:49 pm
Location: On the rock in the 3rd solar orbit.

Re: Moving to the mouse

Post by GMer » Thu Feb 18, 2010 6:08 pm

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.
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

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Re: Moving to the mouse

Post by paradoxnj » Thu Feb 18, 2010 10:49 pm

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....

Post Reply