Game Development Community

wierd problem with container raycast

by Bryce² · in Torque 3D Professional · 01/02/2010 (9:49 pm) · 6 replies

ok ill dump my code first
//------------------------------------------------------------------------------
// RightDown
// This is for starting combat, and looting
//------------------------------------------------------------------------------

function PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
   %ray = VectorScale(%ray, 1000);
   %end = VectorAdd(%start, %ray);
   
   //only search for items
   $SearchMasks = $TypeMasks::ItemObjectType;
   
   //get the player name
   %player = getPlayer();
   
   //scan the area under the cursor
   $scanTarg = ContainerRayCast(%start, %end, $SearchMasks);
   
   //check the scan an perform the corrosponding action
   if ($scanTarg)
   {
      //convert the scan into a variable we can use
      %target = firstWord($scanTarg);
      //grab the distance between the player and the item
      %dist = VectorDist(%player.getPosition(), %target.getPosition());
      
      echo(%dist);
   
      //check if the item is within arms reach and "pick it up"
      if (%dist < 5)
      {
         if( %target.type $= "container" )
         {
            //%target.pickUp();
            Canvas.pushDialog(LootMenu);
            populateLoot(%target);
         }
         else
         {
            %target.pickUp();
         }
      }
   }
}//onRightMouseDown

Heres the problem... it only works on 1 of my item datablocks. It picks up the "Juice" item fine, but the "RareJuice" doesn't work.

here are my datablocks
datablock ItemData(Juice)
{
   //category and name
   category = "foodDrink";
   className = "Drink";
   
   // Basic properties
   shapeFile = "art/shapes/items/bottles/juice/juice.dts";

   // Dynamic properties defined by the scripts
   dispName = "Juice";
   
};

datablock ItemData(RareJuice)
{
   //category and name
   category = "foodDrink";
   className = "Drink";
   
   //Basic properties
   shapeFile = "art/shapes/items/bottles/juice/rareJuice.dts";
   
   //Dynamic properties defined by scripts
   dispName = "Rare Juice";
};

it's been an issue in my game for a while, i gave up on it a few weeks ago, but it has come back to haunt me :(

#1
01/02/2010 (10:18 pm)
Just the other day I was working on object selection with mouse clicks. I had an issue like this, but figured out there was no collision mesh on the object I was trying to select. Maybe thats your issue?
#2
01/03/2010 (2:10 am)
That sounds like it could be my problem as i made all the objects that don't work :)

I'll try that and post back when i find out if it works.
#3
01/03/2010 (4:21 am)
ok it works now thanks for that, but my collision mesh is now the only mesh being rendered.

>bounds
>base01
>>start01
>>>Box2
>>>Cylinder2
>>>col-1
>>detail2
>>Collision-0

Thats my setup, got any ideas?
#4
01/03/2010 (9:25 am)
collision-0 should be collision-1. Also make sure force detail isnt set to something causing it not to render. You can find that in the editor
#5
01/03/2010 (7:16 pm)
thanks Adam, ill try it out when i get the chance...
#6
01/13/2010 (4:38 am)
I know this was a while ago (i forgot about the thread o.O)

IT WORKS! ty Adam... My nubness continues to suprise me ;)