Game Development Community

TGEA fix for 3D Arrow aiming to objective target

by Travis Vroman · in Torque Game Engine Advanced · 03/23/2009 (4:00 pm) · 1 replies

So, I tripped over a recent resource that happened to have exactly what I needed, only it was built around TGE. For the most part, this was not a huge issue, but there were some changes that needed to be made in order to make it work.

The initial resource by Herru Cules D can be found here.

These changes work with TGEA 1.7.1, and I have not tested with other versions.

Don't forget to make backup copies before editing source!

Engine Changes:
engine/T3D/guiObjectView.cpp , Line 302, just under void GuiObjectView::setOrbitDistance(F32 distance) , add:

// 3D Arrow Resource
void GuiObjectView::setRotation(F32 x, F32 y, F32 z)
{
	mCameraRot.x = (x * 1.0f);
    mCameraRot.y = (y * 1.0f);
	mCameraRot.z = (z * 1.0f);
}
// 3D Arrow Resource

engine/T3D/guiObjectView.cpp , at the very bottom of the file, add:

// 3D Arrow Resource
ConsoleMethod(GuiObjectView, setRotation, void, 5, 5,
              "(float x, float y, float z)\n"
              "Sets the rotation for the loaded model..\n\n"
              "\param x x rotation value."
              "\param y y rotation value."
			  "\param z z rotation value.")
{
   argc;
   object->setRotation(dAtof(argv[2]), dAtof(argv[3]), dAtof(argv[4]));
}
// 3D Arrow Resource End

engine/T3D/guiObjectView.h , Line 70, just under void setOrbitDistance(F32 distance); , add:

// 3D Arrow Resource
   void GuiObjectView::setRotation(F32 x, F32 y, F32 z);
   // 3D Arrow Resource End

Save and compile!

Script Changes:

Note that this first change might be due to me using my own model as opposed to the one from the original resource, so you may have to adjust this value.

server/scripts/game.cs , Around line 475, just under %rotation = -1 * (%rotToTarget - %playerRot); , add:

%rotation -= 5;

Soon after that, in the same file, change:
commandToClient(%this, 'SetDirection', %rotation);

to:
commandToClient(%this, 'SetDirection', 0, -15, %rotation);

I also changed the schedule to update every 25 ms instead of every 100 for a smoother result. This is optional. To do this, in the same file, directly beneath the last change, replace:

%this.schedule(100, AimTarget);

with:
%this.schedule(25, AimTarget);

client/scripts/playgui.cs , Around line 74, change the function named function clientCmdSetDirection(%rotation) to look like this:

function clientCmdSetDirection(%x, %y, %z)
{
   %x = -0.5; // Hack to get the arrow to point down some.
   %y = 0; // This value is not really needed at all, so nullify the results.
   direction.setRotation(%x, %y, %z);
   echo(("clientCmdSetDirection rotation: " SPC %x SPC %y SPC %z));   
}

Note that this function is set up to point the arrow down slightly and only rotate along one axis, which is the functionality I needed. However, the c++ function supports rotation on x, y and z so this can be used for what ever you need.

That should be it! Let me know if I left anything out. Enjoy!

#1
10/01/2009 (11:26 am)
thx, works well, just need to change setObject to setModel as well