PlayGui::onRightMouseDown and other commands like it?
by Bryce² · in Torque 3D Professional · 12/09/2009 (1:31 am) · 7 replies
I just found out about these functions recently and I am enjoying my raycast movement.
But I am just wondering what other functions there are like this one. Currently I know these ones
If you know any others, could you please tell me what they are and what they do.
Thanks,
Bryce²
But I am just wondering what other functions there are like this one. Currently I know these ones
PlayGui::onLeftMouseDown PlayGui::onLeftMouseUp PlayGui::onRightMouseDown PlayGui::onRightMouseUp
If you know any others, could you please tell me what they are and what they do.
Thanks,
Bryce²
About the author
Nimansoft, http://www.nimansoft.com/
#2
What I was looking to do was make a diablo style movement. If you are unfamilliar with this, the play walks towards whereever the mouse is held down but when it is released it moves towards the last place where the mouse was held down.
That doesn't make a lot of sense but I hope you can translate my gibber :)
12/09/2009 (3:02 am)
ah kk ty Ted.What I was looking to do was make a diablo style movement. If you are unfamilliar with this, the play walks towards whereever the mouse is held down but when it is released it moves towards the last place where the mouse was held down.
That doesn't make a lot of sense but I hope you can translate my gibber :)
#3
12/09/2009 (10:16 am)
No, it makes plenty of sense. Have you looked at Michael Perry's RTS tutorial? He details a lot of the functionality of click-to-move commands in an RTS environment which is not that different from Diablo-style movement (this is taken from Mitch's tutorial):// onRightMouseDown is called when the right mouse button is clicked in the scene
// %pos is the screen (pixel) coordinates of the mouse click
// %start is the world coordinates of the camera
// %ray is a vector through the viewing
// frustum corresponding to the clicked pixel
function PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
// find end of search vector
%ray = VectorScale(%ray, 2000);
%end = VectorAdd(%start, %ray);
// only care about terrain objects
%searchMasks = $TypeMasks::TerrainObjectType;
// search!
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
// If the terrain object was found in the scan
if( %scanTarg )
{
ClientGroup.getObject(0).player.setMoveDestination( getWords(%scanTarg, 1, 3) );
}
}
#4
The only thing about that code that I don't like is that it is only called evertime i press the mouse, so long distance travel becomes a huge click-spam-o-fest =D
What I need is a function like
If no such function exists, where would be the best place to look at making my own?
12/09/2009 (5:53 pm)
Yes I am using the exact same script, but changed to work with Dan Keller's A* resourcefunction PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
// find end of search vector
%ray = VectorScale(%ray, 2000);
%end = VectorAdd(%start, %ray);
// only care about terrain objects
%searchMasks = $TypeMasks::TerrainObjectType;
// search!
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
// If the terrain object was found in the scan
if( %scanTarg )
{
ClientGroup.getObject(0).player.findPathTo( getWords(%scanTarg, 1, 3) );
}
}The only thing about that code that I don't like is that it is only called evertime i press the mouse, so long distance travel becomes a huge click-spam-o-fest =D
What I need is a function like
function PlayGui::whileRightMouseHeld(%bla, %bla, %bla)
{
//YADA YADA YADA
}If no such function exists, where would be the best place to look at making my own?
#5
Since torque seems to check for press and release then surely doing something repeatedly between the two events is the simplest method?
perhaps even a 100 ms schedule that calls itself and sets the destination?
12/09/2009 (9:21 pm)
I'm far from an expert here but surely something likefunction RightMouseFire(%val)
{
if(%val)
{
Repeat
setdestination()
until MouseRelease
}
else
{
}
}Since torque seems to check for press and release then surely doing something repeatedly between the two events is the simplest method?
perhaps even a 100 ms schedule that calls itself and sets the destination?
#6
If anyone could help me out with this, how do I fix...
12/10/2009 (12:50 am)
I did do this for a while, but it was a bit glitchy and jerky. I am working on adding a onMouseHeld/onRightMouseHeld/onMiddleMouseHeld function into the gameTSCtrl, but it's starting to become more difficult than I had planned on.If anyone could help me out with this, how do I fix...
Error 5 error C2039: 'onRightMouseHeld' : is not a member of 'GuiTSCtrl' c:\Torque\Torque 3D 2009 Pro 1.1 Alpha\Engine\source\T3D\gameTSCtrl.cpp 131
#7
Pitty it is just as effective as having the script straight from the RTS prototype.
excuse my "state the obvious" comments, I need to remind myself constantly :P
12/10/2009 (4:34 am)
Here is my new script (gave up on my c++ changes)function PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
%pressed = getMouseState(0, 1);
mouseMove( %this, %pos, %start, %ray);
}
function PlayGui::onRightMouseUp( %this, %pos, %start, %ray )
{
%pressed = getMouseState(0, 0);
mouseMove( %this, %pos, %start, %ray );
}
function mouseMove( %this, %pos, %start, %ray )
{
//find end of search vector
%ray = VectorScale(%ray, 2000);
%end = VectorAdd(%start, %ray);
//filter everything out of search bar terrain NOTE: will need to change once interiors and other items come into play
%searchMasks = $TypeMasks::TerrainObjectType;
//search
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
//fetch the mouse button state
%pressed = getMouseState(1);
%debug = true;
// echo the two varialbes to the console if debug switch is true;
if (%debug)
{
echo("*** scanTarg = " @ %scanTarg @ " pressed = " @ %pressed @ " ***");
}
// if the terrain was in the ray cast, and the mouse button is still pressed
if (%scanTarg && %pressed)
{
AiPlayerMove(%scanTarg);
schedule(100, 0, "PlayGui::onRightMouseDown", %scanTarg, %pressed);
}
}
function AiPlayerMove(%scanTarg, %pressed)
{
ClientGroup.getObject(0).player.findPathTo(getWords(%scanTarg, 1, 3));
echo("*** scanTarg = " @ %scanTarg @ " pressed = " @ %pressed @ " ***");
}
function getMouseState( %returning, %mouseState ) //two way function, if returning is true it will return the function if returning is false it will set a variable.
{
if ( %returning )
{
return $mouseState; // This may look confusing, but it is a simple concept
} // getMouseState(1) will return the current $mousePos
if ( !%returning ) // getMouseState(0, 1) will set the mouseState to down
{ // getMouseState(0, 0) will set the mouseState to up
$mouseState = %mouseState;
}
}Pitty it is just as effective as having the script straight from the RTS prototype.
excuse my "state the obvious" comments, I need to remind myself constantly :P
Torque 3D Owner Ted Southard