Game Development Community

Item Mouse Over

by Chris McKillip · in Torque 3D Beginner · 09/07/2010 (10:29 pm) · 5 replies

Hey guys,

We're trying to implement items for our game that will glow when moused over. Now, we have a couple of problems.

First, I was able to get item selection to work by using ray casting on a mouse click. Well, kinda. The selection recognizes the health kit and health patch models, but as soon as I start using an item I created (a key), it will no longer recognize the item. My key has a single collision node and 3 LOD levels, and the player will run into it normally when it is instantiated as a collidable mesh. Is there a certain way to set up my .dts so that it will be recognized by the item selection? Here's the selection code I'm using:

// Finds an interactable object in the game world that corresponds to the
// current mouse position on screen.
function PlayGui::onMouseDown(%this, %pos, %start, %ray)
{
   
   // Find the end of the search vector.
   %ray = VectorScale(%ray, $pickLen);
   %end = VectorAdd(%start, %ray);

   // Only care about interactable objects.
   %searchMasks = $TypeMasks::ItemObjectType;

   // Search for any interactable objects along the ray.
   %scanTarg = ContainerRayCast(%start, %end, %searchMasks);
   echo("-------- Left mouse buttom down: " @ %scanTarg);

   // Access the found object.
   if(%scanTarg)
   {
      %target = firstWord(%scanTarg);

      // Make sure that the object is interactable.
      echo("Found interactable item!");
      %target.doMouseOver(0);
   }
}

Second, we wanted to have the items glow as the user moused over them, but we can't seem to find a convenient way to do that. Is there way for an item to access its materials, and can we do that without making everything using the same material glow as well? So far our back-up idea is to do essentially the same thing with item switching - just switch to a different item (or different material for the item) that has the glow effect enabled, but it would be nice if we could just access that aspect of the material directly from the Item or ItemData datablocks.

Thanks for any help or ideas you can give us!

#1
09/13/2010 (5:57 pm)
Well, I found the problem with the mesh. Although we had been exporting a collision mesh, the collision was too small and so wasn't being used for the ray cast. As soon as we made the collision box big enough, it worked out fine. I had tried before to resize the item within the item within the Torque editor, but that didn't matter. I haven't had a chance to really look into it, but my guess is that Torque was culling the item out of the search list for the ray casting code because of the collision box size. Since the item was already culled out, resizing in the editor made no difference. But again, that's kind of just a guess...

Also, in looking to move from using mouse clicks to full mouse overs, I found that the mouse over code doesn't seem to be exposed to script. I think it might actually take a change to the core to expose the function, which is kind of a shame.
#2
09/13/2010 (6:57 pm)
does your item have to glow on selection? I know there was a resource to enable an outline silhouette and overlay when the object was selected, if that would be acceptable. Here is the link:
www.torquepowered.com/community/resources/view/17821

I myself am stymied on object selection and have been trying to figure out how to implement a mouse over functionality (as opposed to mouse down) for object selection. I know there has to be a way to do it, or to get an equivalent functionality, but I think it's gonna take me a good while to figure it out. Please re-post here if you make any headway!
#3
09/14/2010 (2:59 am)
Oh, cool resource. Thanks, Steve! We actually got it working (at least for now) by swapping between materials with glow on or off, but that resource does look a lot more comprehensive.

Yeah, still no progress on actually using mouse move instead of mouse click. We're now looking into doing a core code change to see if we can expose mouse over functionality to script. If we find a good way to do it, though, I'll try to post it here.
#4
10/08/2010 (4:33 pm)
Ok, so we finally managed to get the mouse over stuff working. We ended up making a change to the core code of the GuiTSCtrl, which ended up working fine. However, ironically right after we got that working we noticed that there is a GuiMouseEventCtrl (at least as of Beta 3...) that has an onMouseMove function that could be useful to you. It gives you the mouse position, but you'll have to do your own math to figure out where that relates to world space. Since we already have a working solution, we're not really checking into using the GuiMouseEventCtrl, but it looks like it could do roughly the same thing as we accomplished via our core change. Hope that helps.
#5
10/15/2010 (11:49 am)
Chris, would it be possible to share your implementation? :-)