3D Arrow aiming to objective target
by Herru Cules D · 03/17/2009 (1:52 am) · 30 comments
This resource will give you a 3D arrow (or any object you like) aiming to the target object you want.
This is the preview of how this works.
This resource uses GUIObjectView to load the 3d arrow.
you can download it here www.geocities.com/herrudarmadi/3darrow.zip
place it on data/shapes/direction/arrow.dts
first add this to your server/game.cs
on the client/ui/playgui.gui add
and on the client/playgui.cs add
to get setRotation console method works first:
add this to guiobjectview.h before setCamera()
and at guiobjectview.cc add this before guiobjectview::setcamera
and add this also so that the setrotation can be called from the script
dont forget to rebuild your engine.
how to use it ?
Set the aimTarget method to run automatically just after the player enters the game. here the snippet
just set the $aimTarget to any object id in your mission.
that's it, hope this resource usefull. cheers!
This is the preview of how this works.
This resource uses GUIObjectView to load the 3d arrow.
you can download it here www.geocities.com/herrudarmadi/3darrow.zip
place it on data/shapes/direction/arrow.dts
first add this to your server/game.cs
$aimTarget = 0;
function GameConnection::AimTarget( %this )
{
if($aimTarget)
{
%player = %this.player;
%target = $aimTarget;
%playerTrans = (%player.getTransform());
%xPlayer = getWord(%playerTrans, 0);
%yPlayer = getWord(%playerTrans, 1);
%zRot = getWord(%playerTrans, 5);
%playerRot = getWord(%playerTrans, 6);
%targetPosition = (%target.getPosition());
%xTarget = getWord(%targetPosition, 0);
%yTarget = getWord(%targetPosition, 1);
%xDiff = %xTarget - %xPlayer;
%yDiff = %yTarget - %yPlayer;
// dont have to change it to degrees
// settransform automatically change it to degrees
%rotToTarget = mAtan(%xDiff, %yDiff);
if(%zRot < 0)
%playerRot = (2 * 22/7) - %playerRot;
// multiply by -1 because the rotation in 3dspace is oppositing the guiobjectview rotation
%rotation = -1 * (%rotToTarget - %playerRot);
commandToClient(%this, 'SetDirection', %rotation);
}
%this.schedule(100, AimTarget);
}on the client/ui/playgui.gui add
new GuiObjectView(direction) {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "center";
VertSizing = "bottom";
position = "244 94";
Extent = "149 149";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
applyFilterToChildren = "1";
cameraZRot = "0";
forceFOV = "0";
lightDirection = "-0.57735 -0.57735 -0.57735";
lightColor = "0.6 0.58 0.5 1";
ambientColor = "0.3 0.3 0.3 1";
emapAmount = "1";
};and on the client/playgui.cs add
function PlayGui::onWake(%this)
{
// Turn off any shell sounds...
// alxStop( ... );
$enableDirectInput = "1";
activateDirectInput();
direction.setObject("gb","mod/data/shapes/direction/arrow.dts","","");
// Activate the game's action map
moveMap.push();
}
function clientCmdSetDirection(%rotation)
{
direction.setRotation(0, %rotation );
}to get setRotation console method works first:
add this to guiobjectview.h before setCamera()
void setRotation( const F32 x, const F32 z ); // <- add this void setCamera();
and at guiobjectview.cc add this before guiobjectview::setcamera
void GuiObjectView::setRotation( const F32 x, const F32 z )
{
mCameraRot.x = x;
mCameraRot.z = z;
}and add this also so that the setrotation can be called from the script
// Script function handling for "setRotation"
ConsoleMethod( GuiObjectView, setRotation, void, 4, 4, "ObjectView.setRotation(x,z)" ) {
argc;
GuiObjectView* view = static_cast<GuiObjectView*>( object );
view->setRotation( dAtof(argv[2]), dAtof(argv[3]) );
}dont forget to rebuild your engine.
how to use it ?
Set the aimTarget method to run automatically just after the player enters the game. here the snippet
function GameConnection::onClientEnterGame(%this)
{
// Every client get's a camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Create a player object.
%spawnPoint = pickSpawnPoint("kijang");
%this.createPlayer(%spawnPoint);
// here you go just call the aimTarget here
// and you can set the $aimtarget anywhere and anytime you want.
%this.aimTarget();
}just set the $aimTarget to any object id in your mission.
that's it, hope this resource usefull. cheers!
About the author
#22
to get setRotation console method works first:
add this to guiobjectview.h before setCamera()
and at guiobjectview.cc add this before guiobjectview::setcamera
and add this also so that the setrotation can be called from the script
just like that. hope it helps
04/07/2009 (2:55 am)
@Donnie - yaiks looks like i've altered my guiobjectview a little.to get setRotation console method works first:
add this to guiobjectview.h before setCamera()
void setRotation( const F32 x, const F32 z ); // <- add this void setCamera();
and at guiobjectview.cc add this before guiobjectview::setcamera
void GuiObjectView::setRotation( const F32 x, const F32 z )
{
mCameraRot.x = x;
mCameraRot.z = z;
}and add this also so that the setrotation can be called from the script
// Script function handling for "setRotation"
ConsoleMethod( GuiObjectView, setRotation, void, 4, 4, "ObjectView.setRotation(x,z)" ) {
argc;
GuiObjectView* view = static_cast<GuiObjectView*>( object );
view->setRotation( dAtof(argv[2]), dAtof(argv[3]) );
}just like that. hope it helps
#23
who make this community what it is.......Great Job......Highground
04/07/2009 (5:25 am)
Herru, that was it, thanxs for everything......Its people like you,who make this community what it is.......Great Job......Highground
#24
tge 1.5.2 it works no prob with the above fix for me, however with my other engine that i have with the water upgrade, the arrow doesn't show at all. Its says its loaded and acts like its working just no arrow on screen?????????? No biggy if you can't help just thought i'd let ya know is all................Highground
04/07/2009 (8:24 am)
Herru, One thing of interest though, when I dropped it into a cleantge 1.5.2 it works no prob with the above fix for me, however with my other engine that i have with the water upgrade, the arrow doesn't show at all. Its says its loaded and acts like its working just no arrow on screen?????????? No biggy if you can't help just thought i'd let ya know is all................Highground
#25
After not having had access to my dev box for a while, I now got back to it, didn't get this working and sat down and went over the steps again along with the help from others here and got it working.
TGE 1.5.2, working!
I have one question though, the updating seems "rough", as in the arrow not turning smoothly but rather a bit jaggedly.
It's not biggie but just wondering if someone has an idea as to why, or a fix for that?
On another note, this fits perfectly for my RPG project, along with a few other resources I've tweaked and messed around with.
04/09/2009 (11:34 am)
Thanks everyone for their help :)After not having had access to my dev box for a while, I now got back to it, didn't get this working and sat down and went over the steps again along with the help from others here and got it working.
TGE 1.5.2, working!
I have one question though, the updating seems "rough", as in the arrow not turning smoothly but rather a bit jaggedly.
It's not biggie but just wondering if someone has an idea as to why, or a fix for that?
On another note, this fits perfectly for my RPG project, along with a few other resources I've tweaked and messed around with.
#26
I read up a bit on that TDN page, and I understand how to get the player ID now, but how do I get an ID from a static shape?
Right now my idea is to add a little exec(); at the end of the .mis file just to try out setting the $aimTarget on loading the mission, and I figured I'd try to make the target a marker in a small test-town I threw together.
The "marker" is just a static shape, simply a rock in the middle of the village.
Also I'm wondering how to control the visibility of the arrow, in some way linking it to a Quest or Target system so that objectives are tracked and the arrow is shown either automagically or with a checkbox so the player can choose if he/she wants to have the arrow visible.
Takers? I'll throw in a cake if someone points me in the right direction :)
--EDIT--
I'm giving the cookie to myself as a way to try and get over the fact I'm a noobie.
I sorted it by adding $aimTarget = (towncenter.GetID()); at the end of my .mis file (Where towncenter is what I named the object)
04/09/2009 (3:26 pm)
And just to bug you nice people some more..I read up a bit on that TDN page, and I understand how to get the player ID now, but how do I get an ID from a static shape?
Right now my idea is to add a little exec(); at the end of the .mis file just to try out setting the $aimTarget on loading the mission, and I figured I'd try to make the target a marker in a small test-town I threw together.
The "marker" is just a static shape, simply a rock in the middle of the village.
Also I'm wondering how to control the visibility of the arrow, in some way linking it to a Quest or Target system so that objectives are tracked and the arrow is shown either automagically or with a checkbox so the player can choose if he/she wants to have the arrow visible.
Takers? I'll throw in a cake if someone points me in the right direction :)
--EDIT--
I'm giving the cookie to myself as a way to try and get over the fact I'm a noobie.
I sorted it by adding $aimTarget = (towncenter.GetID()); at the end of my .mis file (Where towncenter is what I named the object)
#27
well done, you've learning fast for "so called newbie" thing.
the $aimtarget is just a global variable, you can set it anywhere you like in your game. for example when entering a big castle, you already set a trigger area there and when the player object enters the trigger it will set the $aimtarget to any object ID you want which you already defined in your mission file or on the fly.
And yes, I use specific object name (must be unique) on the mis file so I could set it anywhere on my game script.
about the visibility of the 3d arrow, you could set the visibility like other gui. just call direction.setvisible(boolean true/false) on the client side.
and the last question about the jerky on 3d arrow rotation is caused the rotation update is set via schedule on the script, it could be better if the update rotation operation done in the engine code (anybody wants to volunteer ??)
well thats it, cheers.
04/10/2009 (2:30 am)
@Marcuswell done, you've learning fast for "so called newbie" thing.
the $aimtarget is just a global variable, you can set it anywhere you like in your game. for example when entering a big castle, you already set a trigger area there and when the player object enters the trigger it will set the $aimtarget to any object ID you want which you already defined in your mission file or on the fly.
And yes, I use specific object name (must be unique) on the mis file so I could set it anywhere on my game script.
about the visibility of the 3d arrow, you could set the visibility like other gui. just call direction.setvisible(boolean true/false) on the client side.
and the last question about the jerky on 3d arrow rotation is caused the rotation update is set via schedule on the script, it could be better if the update rotation operation done in the engine code (anybody wants to volunteer ??)
well thats it, cheers.
#28
So I set up an answer that states "Show me the way to town" which triggers a commandToClient that sets the arrow pointing at a rock in the middle of town which I named towncenter ^_^
I don't know how to set visibility on gui's as I've never tried before but I'm giving it a try tonight =)
I personally would love if someone made a C++ version of this, not that the "jagged" rotation is that bad, it's just one of the things I noticed.
Also, the arrow only rotates, it doesn't tilt (I don't use a locked third person camera) any easy fix for that or that's just how it's done?
Oh, and yeah I'm a noobie, I'm just a stubborn newbie :D
04/10/2009 (6:34 am)
Actually I ended up not putting it in the .mis and instead make it work with an NPC using RPGDialog :DSo I set up an answer that states "Show me the way to town" which triggers a commandToClient that sets the arrow pointing at a rock in the middle of town which I named towncenter ^_^
I don't know how to set visibility on gui's as I've never tried before but I'm giving it a try tonight =)
I personally would love if someone made a C++ version of this, not that the "jagged" rotation is that bad, it's just one of the things I noticed.
Also, the arrow only rotates, it doesn't tilt (I don't use a locked third person camera) any easy fix for that or that's just how it's done?
Oh, and yeah I'm a noobie, I'm just a stubborn newbie :D
#29
I'm getting a "Sorry, the GeoCities web site you were trying to reach is no longer available."
Thanks in advance :-)
03/14/2010 (4:12 pm)
Has anyone a link to the file mentioned in the resource?I'm getting a "Sorry, the GeoCities web site you were trying to reach is no longer available."
Thanks in advance :-)
#30
i recognise this is an old thread buuut
i would love to get this old resource into T3D, but things seem a bit different in the t3d code. has anyone got this working in the 1.1 release ?
07/13/2011 (8:41 pm)
hello i recognise this is an old thread buuut
i would love to get this old resource into T3D, but things seem a bit different in the t3d code. has anyone got this working in the 1.1 release ?

Herru Cules D
about your problem, i think i've already provide the solution at the #8 reply above (http://www.garagegames.com/community/resources/view/16675/1#comment-115729)
after you add the %this.aimTarget(); at the gameconnection::oncliententergame() it will automatically schedule itself, and when the $aimTarget variable is set, it will process the routines.
hope it helps.
@Donnie - I'll try to find the resource link first, i'll post it to you later :)