Game Development Community

Finding position under crosshair

by Ian Morrison · in Torque Game Engine · 01/06/2006 (12:32 pm) · 4 replies

I've done a number of searches on the site, and haven't come up with anything.

What I want to do is have the crosshair in first person mode give me a rangefinder, as in the laser pointer in Tribes 2. I also want to be able to use it to set a marker, similar to how the editors "drop to screen center" setting works.

Where can I look for references on how to do this? I've gone through almost all relevant stock scripts, and I've had trouble finding what I'm looking for in the 500K lines of C++ code in the engine. I'm using Torque 1.3, if that makes a difference. Can I implement what I want in script without issue, or would it be too much of a slowdown?

Thanks!

#1
01/06/2006 (12:39 pm)
I think the enhancements to the Super Crosshair resource had rangefinder capabilities, but I'm not sure.
#2
01/06/2006 (8:09 pm)
I'm no expert yet, but i'd probably create a function that generates a raycast on the client and have the resultant range fed to a gui element for the range finder. wouldnt need to be on the server at all i'd think.

not sure how you'd do the marker though.
#3
01/07/2006 (11:51 am)
Figured it out, with some help from this thread: http://www.garagegames.com/mg/forums/result.thread.php?qt=15719

The rangefinder was actually a feature I wasn't terribly certain of, and may end up dropping altogether. That said, it wouldn't be hard to implement at this point.

Here is my code for finding what the player is looking at and returning a coordinate:

function getTargetRaycast(%obj)
{
%eyeTrans = %obj.getEyeTransform();
%offset = VectorScale(%obj.getEyeVector(),1000);
%eyeEnd = VectorAdd(%eyeTrans,%offset); //A one kilometer effect!

%searchResult = containerRayCast(%eyeTrans, %eyeEnd, $TypeMasks::TerrainObjectType |
$TypeMasks::InteriorObjectType | $TypeMasks::ItemObjectType | $TypeMasks::PlayerObjectType
| $TypeMasks::StaticObjectType , %obj);

%x = getword(%searchResult,1);
%y = getword(%searchResult,2);
%z = getword(%searchResult,3);
%foundObject = %x SPC %y SPC %z;

if(isObject(getword(%searchResult,0)))
{
return %foundObject;
}
else
{
return false;
}
}
#4
01/08/2006 (1:10 am)
Cool, thanks for sharing!