Author Topic: Whats wrong with this raycast?  (Read 619 times)

function fxDTSBrick::calculateNeighbors(%this,%group)
{
   %thisPos = %this.getPosition();
   for(%i=0;%i<%group.getCount();%i++)
   {
      %brick = %group.getObject(%i);
      %pos =  %brick.getPosition();
      %dist = vectorDist(%thisPos,%pos);
      if(%dist <= $Paths::MaxDist && %brick !$= %this)
      {
-snip-
            %ray = containerRayCast(%thisPos,%pos,$TypeMasks::FxBrickAlwaysObjectType,%this);
-debug snip-
            %obj = firstWord(%ray);
               if(isObject(%obj) && %brick.getPosition() $= %obj.getPosition())
            {
               talk("ray works");
               %this.neighbor[%this.neighbors++] = %brick;
            }
      }
-snip-
   }
   %this.neighbors = %this.neighbors++;
}


just focus on the part with the raycast.
it seems to never want to work.
The debugs always show it just returning 0 everytime.
« Last Edit: December 17, 2012, 10:19:38 PM by Brian Smithers »

is it not $TypeMask::?
you have $TypeMasks::. i may just be crazy or something though


i am

Give us a more concise version of your code. I honestly don't have the patience to go reading through your code to find out what your ambiguous variables mean. We're the ones that are going to help you, you should make it easier.

Anyways, your typemasks are a little redundant, fxBrickAlwaysObjectType encompasses all cases where fxBrickObjectType applies

Give us a more concise version of your code. I honestly don't have the patience to go reading through your code to find out what your ambiguous variables mean. We're the ones that are going to help you, you should make it easier.

Anyways, your typemasks are a little redundant, fxBrickAlwaysObjectType encompasses all cases where fxBrickObjectType applies
i removed a part
but the rest is really straight forward.

%self is undefined but that's obviously not your problem



%self is undefined but that's obviously not your problem
didn't change anything.
oh just reread yeah
but it did fix 1 thing.

Have you looked at this if statement?

Quote
Code: [Select]
if(%dist <= $Paths::MaxDist && %brick !$= %self)


I fixed that.

updated OP

Well yeah, but you should actually echo all those values and see if they come out right.

Well yeah, but you should actually echo all those values and see if they come out right.
I do
and they do.
I snipped the debug line.

$TypeMasks::FxBrickObjectType | $TypeMasks::FxBrickAlwaysObjectType
It's because of this. Use $TypeMasks::FxBrickAlwaysObjectType, there is no reason to have both.

It's because of this. Use $TypeMasks::FxBrickAlwaysObjectType, there is no reason to have both.
I changed and it didn't fix

Try using this:

%ray = containerRayCast( %this.position, %brick.position, $TypeMasks::FxBrickAlwaysObjectType, %this );

if ( isObject( %col = firstWord( %ray ) ) && %col == %brick )
{
    echo( %this SPC "hit" SPC %brick );
}


If that doesn't work then the issue is with another part of your code.