Stumbling around for days over this mouse problem
by Matthew W · in Torque Game Engine · 03/31/2008 (6:39 am) · 4 replies
Hi.
So far we have it so that when the player holds the right mouse button down, they are able to move the camera around:
from GameThrii/client/default.bind.cs
Now i've been trying and trying and trying to make it so that clicking with the left mouse button (button0)moves the player to whereever you clicked. So far i have followed this nice resource starting with a brand new installation of TGE. i've successfully have reached a point where in this new install, clicking with button0 does move the player across the screen to the clicked point! Here's the code:
from GameThrii/client/commander.cs
Now im failing to use this code successfully in our game we've been working on; i'm kind of frustratingly exahsted now! So in engine/editor/worldEditor.cc i've modified the resource code, there to read:
matthew
So far we have it so that when the player holds the right mouse button down, they are able to move the camera around:
from GameThrii/client/default.bind.cs
moveMap.bind( mouse, button0, button0Clicked );
moveMap.bind( mouse, button1, button1Clicked );
moveMap.bind( mouse, zaxis, zoomCamera);
function button1Clicked(%val) {
if (%val) {
CursorOff();
moveMap.bind( mouse, xaxis, rotateCameraHorizontal);
moveMap.bind( mouse, yaxis, rotateCameraVertical);
}
else {
moveMap.unbind( mouse, xaxis );
moveMap.unbind( mouse, yaxis );
CursorOn();
}
} //.Now i've been trying and trying and trying to make it so that clicking with the left mouse button (button0)moves the player to whereever you clicked. So far i have followed this nice resource starting with a brand new installation of TGE. i've successfully have reached a point where in this new install, clicking with button0 does move the player across the screen to the clicked point! Here's the code:
from GameThrii/client/commander.cs
function Commander::[i]onLeftMouseDown[/i](%this)
{
echo("onLeftMouseDown entered");
%pos = %this.getMouse3DPos();
%cl = ClientGroup.getObject( 0 );
//Do stuff here with the client... to acces the player object of
//this client, use %cl.player
%cl.player.moveTo(%pos);
}Now im failing to use this code successfully in our game we've been working on; i'm kind of frustratingly exahsted now! So in engine/editor/worldEditor.cc i've modified the resource code, there to read:
void WorldEditor::on3DMouseDown(const Gui3DMouseEvent & event)
{
//... the regular code here ...
Con::executef(this, 1, "[i]onLeftMouseDown[/i]"); //matthew
}because the resource uses the right mouse button for click to move and we want to use button0. Also the previous section of code up there (the one from GameThrii/client/commander.cs) is also changed from the resource, but it all works fine in the brand-new torque installation, remember? And i've added all of the other changes that were requested by the nice resource. :) Now when i click with button0 nothing happens.. it doesnt echo "onLeftMouseDown entered". i'm not sure what is happening there. Most recently i tried adding this to the defalut.bind.cs code:moveMap.bind( mouse, button0, button0Clicked );
function button0Clicked(%val) {
Commander::onLeftMouseDown(%this);
}but, this didnt help. Well, i just cant figure out why onLeftMouseDown is never called? i've searched the code in example/tutorial.rts (in that brand new installation) with ExamDiff comparing the nice resource's code with tutorial.base. A very helpful program.. though it hasn't helped me fix this. i've searched the brand new installation tutorial.rts folder and our game folder,GameThrii, too with Codeweaver. So ive searched and compared and changed and unmade these changes for a really long long time. Honestly, i cant think of anything else to try. :(matthew
#2
http://216.116.32.49/index.php?sec=mg&mod=resource&page=view&qid=14265
and is for creating an RTS-like game without having RTS, i think. :)
03/31/2008 (9:28 am)
Well but it is for TGE, i dont have RTS. The 'nice resource' link in the code above goes to here:http://216.116.32.49/index.php?sec=mg&mod=resource&page=view&qid=14265
and is for creating an RTS-like game without having RTS, i think. :)
#3
@Matthew: Ive not played around with this code but ive implemented something similar myself. Not got time right now to look through but from what i remember, dosent it already have left click set up in the scripts?
03/31/2008 (9:45 am)
@Shon: Hes in the right place :P He isn't using the RTS starter kit just some code that someone posted to emulate basic RTS functions. ( http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=14265 )@Matthew: Ive not played around with this code but ive implemented something similar myself. Not got time right now to look through but from what i remember, dosent it already have left click set up in the scripts?
#4
03/31/2008 (9:57 am)
@Henry: Yes it does and the left click button is commented for //Place a building, but ive deleted all of that code and replaced it with the way to get the character to move. This new code is presented up there ^
Torque Owner Shon Gale
garagegames.com/mg/forums/result.forum.php?qf=140