Game Development Community

ContainerRayCast with RTS View

by Robert Stewart · in Torque Game Engine · 10/26/2004 (10:03 am) · 9 replies

Hello, I have a Topdown (RTS) veiw and iam trying to click on the terrain and have Selected Object, move to that spot on terrain, at the moment this is not working, when i click on terrain at location ("100 100 100 ") the player moves to position ("243 364 223"), Here is my code.
%selectRange = 2000; 
%mouseScaled = VectorScale(%mouseVec, %selectRange); 
%rangeEnd = VectorAdd(%cameraPoint, %mouseScaled);
%searchMasks = $TypeMasks::PlayerObjectType | $TypeMasks::CorpseObjectType |
$TypeMasks::ItemObjectType | $TypeMasks::TriggerObjectType;
%scanTarg = ContainerRayCast (%cameraPoint, %rangeEnd, %searchMasks);

echo("function ServerSelectObject launched");

// a target in range was found so select it
if (%scanTarg)
{
echo("selection found");
%targetObject = firstWord(%scanTarg);

%client.setSelectedObj(%targetObject);
return;
}

%searchMasks = $TypeMasks::TerrainObjectType | $TypeMasks::CorpseObjectType |
$TypeMasks::ItemObjectType | $TypeMasks::TriggerObjectType;

%scanTarg = ContainerRayCast (%cameraPoint, %rangeEnd, %searchMasks);
echo("Ray launch for pos");

if (%scanTarg)
{
echo("pos found");
%targetObject = %client.getSelectedObj();
if ( %targetObject )
{
echo("obj found");
$pos = getWords(%scanTarg,1,3);
%targetObject.setMoveDestination($pos);
echo("Moving to "@ $pos );
}
}

#1
10/26/2004 (10:10 am)
Is there someway i can make the (Ai)player move from the (AI)Players EyeView, instead of using the camera? because i think the camera view is my problem, thanks.
#2
10/26/2004 (1:11 pm)
Anybody understand this?
#4
10/26/2004 (11:57 pm)
I didn't plug your code in and test it, but for some reason this line looks wrong:

$pos = getWords(%scanTarg,1,3);

Instead, I think this will return the X,Y,Z positions:

$pos = getWords(%scanTarg, 0, 2);

This should get the value at index zero, and then get the 2 words after.

I don't know if that will clear up your problem completely but it should fix something, unless you intended to get "Ypos, Zpos, Xquat, Yquat"
#5
10/27/2004 (12:13 am)
Quote:
Is there someway i can make the (Ai)player move from the (AI)Players EyeView, instead of using the camera? because i think the camera view is my problem

Also, I don't think you want to do that. The clickable terrain algos raycast camera-to-world, not playerEyeView-to-world (unless the camera happens to be first person). Re-routing/Translating a mouse click through a third-person entity gives me a headache just thinking about it, and in the best case scenario it would simply give the same results as camera-to-world raycast.

Once you translated the mouseclick into a 3D world position, you can raycast from the player/AIPlayer eyePosition to the world position to determine if the player has a clear line-of-sight. I think the AIPlayer already does this to determine if it can fire.
#6
10/27/2004 (7:04 am)
I havent been able to implement Click n Pick with either TGE 1.2 or 1.3 can someone show me how this might be done, randall ill test what this does %pos = getWords(%scanTarg, 0, 2); thanks
#7
10/27/2004 (11:43 am)
Wait, nevermind, I was tired last night.

%scanTarg returns this: (TargetObject, X, Y, Z).

So the code *should* be:

%pos = getWords(%scanTarg, 1, 2);

or alternately:

%pos =  getWord(%scanTarg,1) SPC getWord(%scanTarg,2) SPC getWord(%scanTarg,3);
#8
10/27/2004 (11:57 am)
I found "Click n Pick" to be a huge waste of time, simply because it is in a patch format. This is mostly due to my own incompetence- I don't know how to apply the patch and can't dissect the patch to fix incompatibilites with the current Head. A better option might be:

Object selection in Torque

looks kind of scary, but it isn't. I was able to apply the code and get a fully clickable world in about half an hour. The author goes over each bit of code briefly to tell you what is going on. Just be sure to sure to scroll all the way down and read Orion Elenzil' post from Aug 25, 2004. His "corrections" fix a lot of problems.
#9
10/27/2004 (2:09 pm)
I have got Click n Pick to work, thanks, if anyone wants help setting it up just email me.