Game Development Community

accurate spawn surface

by Gibby · in Torque 3D Professional · 04/14/2014 (7:14 pm) · 5 replies

Greets all:

I've been trying to find an accurate way to find the z-axis position of the level at which to spawn objects. In this video you can see that I have a terrain object and TSStatic street/building pieces scattered about the level.


My challenge is that if use containerRaycast, to find the surface object, and the surface is a TerrainObjectType, I get a radically different z-axis value than if the raycast is a $TypeMasks::StaticTSObjectType. In the world editor, the terrain position is 1024 1024 -512 and the street pieces are all at %x %y 0.0. How do i get the correct value of the z-axis for both terrain and shapes?

#1
04/14/2014 (9:27 pm)
10-1 you're already using:
%mask = $TypeMasks::ShapeBaseObjectType;
%scanTarg = ContainerRayCast (%eyePoint, %targetPoint, %mask, %obj);
if (%scanTarg)
{
   %targetId = getWord(%scanTarg,0);
   %targetPoint = getWords(%scanTarg,1,3);
or an equivalent.

the inverse example there would be:
// Apply damage to the object all shape base objects
if ( %col.getType() & $TypeMasks::ShapeBaseObjectType )
where %col would correspond to the equivalent %targetId entry from the first example.

combine that with looking up your type (listed in [url]https://github.com/GarageGames/Torque3D/blob/master/Engine/source/T3D/gameFunctions.cpp#L431 [/url] )

and that should give you a switch to apply an offset from. say, somethin like...

%mask = $TypeMasks::ShapeBaseObjectType | $TypeMasks::TerrainObjectType;
%scanTarg = ContainerRayCast (%pointA, %pointB, %mask, %obj);
if (%scanTarg)
{
   %rayHit = getWord(%scanTarg,0);
   %targetPoint = getWords(%scanTarg,1,3);
   %pos = %rayHit.getPosition();
   if ( %rayHit.getType() & $TypeMasks::TerrainObjectType ) 
   {
      %targetPoint += %pos;
   }
}

(Not 100% sure on that, but should be a decent starting point, at least. I will say I find it rather odd that you'd be getting skewed values from %targetPoint though...)
#2
04/15/2014 (6:54 am)
Reading your initial question and watching the video I can't see that it makes a functional difference. Are things spawning at -512 units when they're supposed to spawn on a static object (like the street, for instance)? I'll admit I haven't tried this - so I am curious what it's actually doing.
#3
04/15/2014 (7:18 am)
$TypeMasks::StaticTSObjectType isn't a thing since 1.2 ...
$TypeMasks::StaticObjectType and $TypeMasks::StaticShapeObjectType are the new thing ... and basically do the same thing, meaning staticShapes cannot be resolved over TsStatics via a lone typemask ... because ... reasons ... apparently ...
#4
04/15/2014 (9:11 am)
Steve's got it right there. If you want to filter between the different objects, you'll need to use some of the common functions between objects such as .getClassName() or even plain old .getDatablock().getName()

This would obviously go after scanning the typemask.
#5
04/17/2014 (7:02 pm)
@Steve y Robert: Thanks guys that was it!!!