RTS-style right click movement

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
coder543
Posts: 17
Joined: Sun May 31, 2009 4:40 pm

RTS-style right click movement

Post by coder543 »

I am currently implementing a game with several stylistic influences, but I need to be able to move these units to a location simply by right clicking.

Basic info:

Space based game, meaning no floor mesh.
Assume that I have selected only one unit, using the ISceneMeshNode* name of "current"
Units are unable to move on the 3rd dimension, they are limited to 2d movements.

Does anyone know how to do this?
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Get the ray that starts at the position the current camera and goes in the direction the camera is looking at (ISceneManager::getSceneCollisionManager() )
Get the collision point of this ray and the plane where your units walk over ( plane3d::getCollisionWithLine() for example)
And then move the node to this position. (For example using a FlyStraightAnimator)
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
cr33
Posts: 22
Joined: Fri Mar 27, 2009 3:37 pm

Post by cr33 »

i dunno if i understood correctly, if are able to move in 2d but not 3d

look how it was done in HOMEWORLD

click/press button to grap 'move tool' :P, and move mouse on 2d plane, roll mouse scroll to move up/down
coder543
Posts: 17
Joined: Sun May 31, 2009 4:40 pm

Post by coder543 »

The homeworld style would be acceptable, with two problems. One, I would still need to get a ray trace onto a nonexistant plane in order to determine where to expand the circle to. And two, I would have to draw a circle, something I am not familiar with doing.

I would like to have an 'assumed' plane. This means that somehow I would like to be able to have all the units on the same given plane, then be able to right click and determine a coordinate for that right click.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Code: Select all

plane3df( vector3df( 0,0,0 ), vector3df(0, 1, 0 ) );
This constructs a plane spanning the XZ Axis.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
coder543
Posts: 17
Joined: Sun May 31, 2009 4:40 pm

Post by coder543 »

But wouldn't that defeat the whole purpose of the space game appearing to not have a plane? Or can you click on a fully invisible plane?
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

plane3df is just a data structure. It has no graphical representation unless you draw it yourself.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
coder543
Posts: 17
Joined: Sun May 31, 2009 4:40 pm

Post by coder543 »

from the documentation for getIntersectionWithLine() (http://irrlicht.sourceforge.net/docu/cl ... 88721e2f30)

[...]
lineVect Vector of the line to intersect with.
linePoint Point of the line to intersect with.
outIntersection Place to store the intersection point, if there is one.
[...]

How could I possibly know the point of the line to intersect with? I have a ray from getRayFromScreenCoordinates (core::position2d< s32 > pos, ICameraSceneNode *camera=0) to put into lineVect, but linePoint?!?!?!?!?
HELP!! that's the worst idea! I am very confused by this documentation of getIntersectionWithLine.

What am I supposed to insert into linePoint???
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

wtf? this is still so unclear...
I stumbled upon that some time ago too ^^

It should better be point of the line to test for

For the point you can use the end, the start, or the middle of the line.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
coder543
Posts: 17
Joined: Sun May 31, 2009 4:40 pm

Post by coder543 »

can you tell me how it should look in code?

Assuming that tRay is the ray coming from the screen coordinate, and tPlane is the plane of movement.

I don't know exactly what to do with the variables even now.
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Use getIntersectionWithLimitedLine(...). It's parameters are much more obvious, and if you're using a ray from screen coordinates and you can see where you're clicking (and the camera's far plane is thus beyond that point) then your line will pass through the plane (so it doesn't matter if its limited).
coder543
Posts: 17
Joined: Sun May 31, 2009 4:40 pm

Post by coder543 »

ok, thanks
Post Reply