Game Development Community

Throw object at Mouse pointer Position

by Greyfort · in Torque 3D Beginner · 12/19/2011 (11:06 pm) · 9 replies

This is my function called in the PlayGui file, Why is is not createing item? I'm stummped If anyone can help I would be thankful.

platform: Windows,Torque T3D pro, Licensed.

function PlayGui::OnControlDropped( %this, %payload, %position )
{
echo( "PlayGui::OnControlDropped( " @ %this @ ", "@ %payload @ ", " @ %position @ " )" );
echo( "PlayGui::onMouseUp( " @ %this @ ", " @ %pos @ ", " @ %start @ ", " @ %ray @ ", " @ %mouseClick @ " )" );


echo( "DROP ON GROUND: %this.position " @ %this.position );
echo( "DROP ON GROUND: %position " @ %position );
echo( " isObject=[ "@isObject(HealthKitPatch)@" ]");

HealthKitPatch.onThrow();
}

About the author

Computer programming/repair,3D Modeling,anim,Game Dev.


#1
12/29/2011 (11:52 pm)
Look into the scene tree and call HealthKitPatch.onThrow()
If a new item appears,then you are creating them below the terrain.
#2
12/30/2011 (7:18 pm)
You are correct it appears under the terrain:

I changed this in item.cs

%obj = new Item()
{
datablock = %this;
position ="0 0 20";
rotation = "0 0 1 "@ (getRandom() * 360);
count = %amount;
};

now it appears at -2?? 2 hundred something in the minus.
what am I doing wrong?
#3
12/31/2011 (1:24 am)
Check your terrain's height before spawning items.
You still create them below the terrain.
#4
12/31/2011 (7:05 pm)
Ok well I want it to be dynamic so...

How in a terrain that goes up and down (varies) would you get it to spawn above terrain? I tried the position but that is the gui or f2 I want it to be f3 of the terrain.
I tried making the raycast a global but I get syntax error with [%Fchkpos = $chkEnd;] in the code below:

%obj = new Item()
{ //$chkEnd
datablock = %this;
// custom code start
%Fchkpos = $chkEnd;
%xPos = getWord(%Fchkpos, 0);
%yPos = getWord(%Fchkpos, 1);
%zPos = getWord(%Fchkpos, 2);
%NzPOS = %zPos + 2.0;
%Npos = %xPos SPC %yPos SPC %NzPos;
position =%Npos;//$chkEnd; //"0 0 +20";
echo( "ITEM POS DATA::( $chkEnd:["@ $chkEnd @ "]");
echo( "ITEM POS DATA::( xPOS:["@ %xPos @ "] yPOS:[" @ %yPos @ "] zPOS:[" @ %zPos @ "]" );
echo( "ITEM POS DATA::( %NzPOS:["@ %NzPOS @ "]");
echo( "ITEM POS DATA::( position:["@ %Npos @ "]");
// custom code end
rotation = "0 0 1 "@ (getRandom() * 360);
count = %amount;
};

logically it seems right, I just must be doing torque script wrong?
#5
01/04/2012 (12:34 pm)
Greyfort@ Just an idea ... but you could always just make the height "really high" (+100z or such) and the object will fall down to the terrain ... might need to make it "sticky" so it doesn't bounce too much.

#6
01/05/2012 (4:55 pm)
Try getTerrainHeight. (TDN getTerrainHeight)
This is documentation for TGE, but I think it's still included in T3D.

You still might have to adjust the value to make it spawn just above the ground.
#7
01/17/2012 (1:53 pm)
The following will spawn an object at the clicked spot if you have your cursor shown and you put this in PlayGui::onRightMouseDown():

// onRightMouseDown is called when the right mouse button is clicked in the scene
// %pos is the screen (pixel) coordinates of the mouse click
// %start is the world coordinates of the camera
// %ray is a vector through the viewing
// frustum corresponding to the clicked pixel
function PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
   // find end of search vector
   %ray = VectorScale(%ray, 2000);
   %end = VectorAdd(%start, %ray);
    
   // only care about terrain objects
   %searchMasks = $TypeMasks::TerrainObjectType;
 
   // search!
   %scanTarg = ContainerRayCast( %start, %end, %searchMasks );
    
   // If the terrain object was found in the scan
   if( %scanTarg )
   {
      // spawn a new object at the intersection point
      %obj = new TSStatic()
      {
         position = getWords(%scanTarg, 1, 3);
         shapeName = "art/shapes/building/orcburrow.dts";
         collisionType = "Visible Mesh";
         scale = "0.5 0.5 0.5";
      };
 
      // Add the new object to the MissionCleanup group
      MissionCleanup.add(%obj);
   }
}

Replace the orc burrow by putting your object in for the shapeName field. From the RTS Prototype example in the Torque 3D official scripting documentation....
#8
01/17/2012 (1:57 pm)
Oh thanks Rich, I saw you do this with a camera demo and you made the PC walk to the GG logo, as the camera angle changed depending on ware PC was.

I saw this in the demo, I hadn't even thought about it for simulating dropping item from inventory. Leave it to me to make it more complicated. i will try it and let you know how it goes.
#9
01/17/2012 (5:28 pm)
That was the first time it created the item above the terrain. It seems my issue is that im dragging a guidragdrop icon over the terrain and want it to drop there. emulating dropping a item from your inventory. This method works once.

What seems to happen is if I click the terrain before I remove the item from my inventory it will create object on terrain. But if i open inventory and then drag and drop no creation.

What im trying to do is have a default 3d object drop on terrain if a set one isn't given for the object.

Example: healthkit invy icon click/hold/drag to terrain
1) check icon for object tag
if ( $iconvariable $= ""){$iconvariable="bag";}

2) then drop(create item)

// spawn a new object at the intersection point
%obj = new TSStatic()
{
position = getWords($STarg, 1, 3);
shapeName = "art/shapes/items/kit/"@$iconvariable@".dts";
collisionType = "Visible Mesh";
scale = "0.5 0.5 0.5";
};

And i must click on the terrain before dragdrop invy icon to create item (then it creates it)

Other wise still no creation of item if i drag and drop from gui