Game Development Community

Problem with determining mouse positition.

by Jason Gossiaux · in Torque Game Engine · 04/07/2008 (1:39 am) · 1 replies

For a while now I've been using a GameTSCtrl Gui element with a .cs file to capture onMouseDown() events and pass the mouse coordinates to a server side function. This works great for sending bots to places around the map at the click of a mouse.

However I recently found the need to use the OnMouseMove event. So I edited the source to throw a callback onMouseMove and the following function gets called:

function BuildGui::onMouseMove(%this)
{
%mouseVec = %this.getMouse3DVec();
// cameraPoint = the world position of the camera
%cameraPoint = %this.getMouse3DPos();
commandToServer('RefreshPlot', %mouseVec, %CameraPoint);
}

My problem is the position returned from getMouse3DVec and getMouse3DPos do NOT update as I move the mouse around. They only update if I click someplace on the GUI, and then forever repeat that value until I click again!

Does anyone know why this might be occuring? I am trying to have the player enter a "build mode" via a button on the custom GUI. Then an FxRenderObject is created and tracks the mouse as it moves over the terrain just like any good old RTS. Its almost perfect - except in the current state it only updates when I click a button :/ Thanks in advance for any help with this.

#1
04/07/2008 (2:02 am)
Heh, I post... and then figure it out. Never fails :P

It turns out the OnMouseMove engine call wasn't as complete as the OnMouseDown engine call. Specifically it didn't fill in the mouse position fields.

So now I can click the build button and wherever the cursor is on the terrain a rectangular plot texture is drawn below it, just like most of your typical RTS games. I figure the plot outline is good enough for now and I can always get fancy with a shaded out representation of the DTS/DIF model later.

One thing I don't like is that if the player walks forwards or backwards the plot outline stays in the same spot because technically the mouse hasn't moved. I think I have an idea for fixing it though.

Has anyone done this as a resource yet or would it be something people might find useful? Searching for anything with RTS in it turns up quite the gaggle of stuff from the paid package and its hard to find anything for standard TGE/A.