Gui Reticle HUD for TGE(A) With Target Cycling
by Martin Schultz · 12/17/2007 (7:59 am) · 67 comments
Download Code File
This resource contains a gui control element which displays a rectangle around every shape in the view frustrum and displays the currently selected shape in a different color (target selection). The display style of the rectangles can be chosen between full rectangles and rendering only the corners around the shape. Furthermore the normal / selected colors can be freely chosen as well as the minimum size of the rectangle once the shape is very far away (minimum rectangle size).
Cycling through the targets is done by using the mouse wheel. The client transmits then the selected ghost id to the server and the server then does a lookup to find out the server player id. The id is then stored in the %client variable for the corresponding client. This player id can then be used in an weapon onFire function to actually track the target for example when using a homing missile.
The attached zip cointains a readme file and the source file for TGE and TGEA.
Please note that the target cycling code is somewhat buggy and not battle-proven, so excuse that the cycling code is not perfect yet. Will improve this soon. :-)
This resource contains a gui control element which displays a rectangle around every shape in the view frustrum and displays the currently selected shape in a different color (target selection). The display style of the rectangles can be chosen between full rectangles and rendering only the corners around the shape. Furthermore the normal / selected colors can be freely chosen as well as the minimum size of the rectangle once the shape is very far away (minimum rectangle size).
Cycling through the targets is done by using the mouse wheel. The client transmits then the selected ghost id to the server and the server then does a lookup to find out the server player id. The id is then stored in the %client variable for the corresponding client. This player id can then be used in an weapon onFire function to actually track the target for example when using a homing missile.
The attached zip cointains a readme file and the source file for TGE and TGEA.
Please note that the target cycling code is somewhat buggy and not battle-proven, so excuse that the cycling code is not perfect yet. Will improve this soon. :-)
#22
12/21/2007 (2:32 am)
The function cycleTargetsMouseWheel seems to be never called.
#23
12/21/2007 (2:33 am)
That's the problem. It is not setup in the corresponding config file (where all the mapping is done).
#24
12/21/2007 (2:34 am)
It's in the config.cs file:moveMap.bind(mouse0, "zaxis", cycleTargetsMouseWheel);but still doesn't work!
#25
12/21/2007 (5:01 am)
Got it working
#26
12/21/2007 (5:02 am)
Good, what was the solution?
#27
Now I want to modify this, to shot always the selected target. Just like in Tomb Raider... I thought about a way doing this:
Replace the onFire function of the weapon with a function that points at the target.
But, how to get the target and its position?
12/21/2007 (5:26 am)
The function was called. I just set the wrong $SendWheelScroll property and as solution I just deleted:if (!$SendScrollWheel)
return; // if not allowed to sendThis not neccessary for me, every weapon is allowed to send. Just a question:Now I want to modify this, to shot always the selected target. Just like in Tomb Raider... I thought about a way doing this:
Replace the onFire function of the weapon with a function that points at the target.
But, how to get the target and its position?
#28
12/21/2007 (5:32 am)
Quite simple, in the onFire function set for every projectile the target id that got transmitted by the function that selected a target on the client. Then every projectile fires at the target you want to have (oh, sorry that was from the Flight Game Example with its autotargeting projectiles). Well, if you have the target, then do a target.getTransform() or target.getPosition() to get the location to fire at.
#29
12/21/2007 (5:39 am)
sorry, it's the first time that I work with projectiles. I've got this onfire code:function GroundMajorWeaponImage::onFire(%this, %obj, %slot)
{
%projectile = %this.projectile;
// Decrement inventory ammo. The image's ammo state is update
// automatically by the ammo inventory hooks.
%obj.decInventory(%this.ammo,1);
// Determin initial projectile velocity based on the
// gun's muzzle point and the object's current velocity
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));
// Create the projectile object
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
// New code here:
if (%obj.client.isAIControlled())
{
// auto-check for new targets every second for the AI players
%p.checkForTargets(%obj);
}
else
{
if (0 != %obj.client.reticleTarget) // set target only if target is a valid object
{
%p.setNewTarget(%obj.client.reticleTarget);
if (isObject(%obj.client) && ! %obj.client.reticleTarget.client.isAIControlled())
commandToClient(%obj.client.reticleTarget.client, 'MissileFire', %p);
}
}
// End new code
return %p;
}How do I get the target now and how to set the location to fire at?
#30
12/21/2007 (5:43 am)
The target is stored in %obj.client.reticleTarget. So %obj.client.reticleTarget.getPosition() gets the position of your target. Do a %obj.client.reticleTarget.dump(); (after the MissionCleanup(%p)) in there to see what object you got there.
#31
12/21/2007 (5:46 am)
Thanks, the really interesting thing for me is only the %obj.client.reticleTarget.getPosition(), but how do I modify the projectile now to fire at this point?
#32
12/21/2007 (5:49 am)
Good question :-) No clue.
#33
12/21/2007 (5:51 am)
to bad that I don't have the money for the flight game example
#34
12/21/2007 (6:29 am)
Found out
#35
Is there a potential problem if the target object is destroyed and replaced with another object with the same address? It would match on the target address compare in the render method but it is really another object? In my variant I'm going to save the object ID as well so that can be compared if the addresses match. Does that make sense? thanks
01/05/2008 (5:44 am)
Great resource, thanks Martin, you are very generous. Is there a potential problem if the target object is destroyed and replaced with another object with the same address? It would match on the target address compare in the render method but it is really another object? In my variant I'm going to save the object ID as well so that can be compared if the addresses match. Does that make sense? thanks
#36
01/05/2008 (12:05 pm)
No, the ID's will never be the same, so if one object is destroyed and a new one replaces the selected target, it will have a different id, so no problem there.
#37
04/19/2008 (9:18 pm)
Hey, any way I can get this to show targeting boxes for only players and vehicles? I've noticed that I can target my own vehicle too, it'd be nice if there was a way to prevent that.
#38
04/20/2008 (12:10 am)
Anyway to thicken the recticle lines? It's hard to see them.
#39
- Ally
- Enemy
- Citizen
- Vehicle
- Player
- Shape (buildings etc)
Hopefully this will help you. Stay tuned.
04/20/2008 (7:51 am)
@Maddermadcat - I'm interested in doing this too. Currently I'm modding the source of GuiReticleHud so I can show a bitmap instead which you can specify from the mission editor. Then I'm going to provide the class with the classification of each object via a console method. In my instance I am going to send - Ally
- Enemy
- Citizen
- Vehicle
- Player
- Shape (buildings etc)
Hopefully this will help you. Stay tuned.
#40
04/20/2008 (10:16 am)
Alright. Thanks, Andy, looking forward to it. :] 
Torque Owner Martin Schultz