Game Development Community

Raycasts dont fire on polysoup TSStatics?

by Adam Beer · in Torque 3D Professional · 04/07/2010 (10:22 am) · 11 replies

I am trying to do a check as to whether a player can see a marker from the current position and I am only worried about the ray hitting TSStatics with polysoup enabled.

%ray = ContainerRayCast(%this.player.getPosition(),%node.getPosition(),$TypeMasks::StaticObjectType);
			%hitPosition = getWords(%ray,1,3);
			echo("Hit Pos: " @ %hitPosition);

			if(%hitPosition != %node.getPosition())
			{
				%nodeFR1 = %this.path.getObject(%node.fr);
				%this.moveToNode(%nodeFR);
			}

%hitPosition doesnt seem to get anything and I know for sure that the ray should be hitting something. Do raycasts just not work on polysoup or am I getting the hit position incorrectly?

Edit: %this.player.getPosition() and %node.getPosition() are returning values correctly.

#1
04/07/2010 (10:49 am)
Try again with StaticTSObjectType
#2
04/07/2010 (10:51 am)
That didnt do it.
#3
04/07/2010 (1:38 pm)
Are you sure your start-end positions are correct ?
This seems to be an issue only in script. On the c++ side it works.
#4
04/07/2010 (2:31 pm)
Yes, positions were the first thing I checked. They are both set right.
#5
04/07/2010 (2:56 pm)
So what you're trying to do is check if the path is clear correct?

Here's my version of the same idea, just checking if anything is in the way so it only returns the first thing it hits (firstWord).

//%this is the player/AI firing the raycast ... obviously

   %eyeTrans = %this.getEyePoint();
   %eyeEnd = %goal.getTransform();

   %searchResult = containerRayCast(%eyeTrans, %eyeEnd, $TypeMasks::StaticTSObjectType, %this);

   %foundObject = firstWord(%searchResult);
   if(!%foundObject) return true;   // path is clear
   else return false; //path is blocked
#6
04/07/2010 (4:58 pm)
Are you sure that this node is a TSStatic? Some resources on the site work with AI traversal nodes that are descendants of the MissionMarker class, for example. (Though afaik that should still fire for you.. but not for the Player which you don't hide from the raycast)

Perhaps your player is %this instead of %this.player? Are you sure your parameters in the first line of your code are what you need them to be?

Also, once you fix that, refering to %nodeFR and %nodeFR1 would cause more headaches. Perhaps both should be %nodeFR?

Edit: Or did you mean to pass %node.fr.getPosition() as a parameter for the raycast? Just guessing here, hoping it gives you new ideas.
#7
04/07/2010 (8:34 pm)
The situation is an AI aircraft that spawns and tries to go along a path. If the node it tries to go to isnt reachable (hence the player->node raycast). It sees if there is anything in the way stopping the player from going to that node and if there is, it has to go to a "first reachable" node. The problem is I am doing a raycast from the player's position to the position of the node to travel to and in the way is a TSStatic with polysoup. The raycast doesnt seem to give the position at which it hit the TSStatic so I can only assume that polysoup doesnt work with raycasts.

Is this the case or am I just getting the position of the "hit" wrong?
#8
04/08/2010 (12:06 am)
I'm sure raycasts work with polysoup. The problem must be something else.
#9
04/08/2010 (7:02 am)
Adam, you do know that you're missing the first word return? Which is zero, so getWords(%ray,1,3) is starting with the 2nd word and ignoring the first one --- if such things are there to be hit. (%ray,0,3)

Quote:
getWords

%word = getWords(%string, %startPos, %endPos);

Extracts all space-delimited words from a string, starting at the %startPos position in the string and ending at the %endPos position. Note that the first word of a string is position 0.

For example, if %string is "Who's your daddy?", getWords(%string, 0, 1); will return Who's your.

From TDN ... which is apparently your .... er ... Daddy

EDIT: a cup of tea later and I realize that ... yes, you do know.

Check that you actually do have "visible collision" enabled (not as daft as it sounds...) and put in an extra echo above the raycast to check that the function is getting called at all.
#10
04/08/2010 (7:52 am)
Thanks guys I got it to work. I tried steves code @ #5 and that did it - along with a few other logic changes. Really appreciate the help!