About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Raycast - What did I click on?
Author Message
rstralberg Offline
Member

Post: #1
Raycast - What did I click on?
I use this code below to check where I click with the mouse on something

Code:
Vec pos;
      Vec dir;      
      ScreenToPosDir(Ms.pos(), pos, dir);
      pos.z += 0.6; // we need to be outside our own mesh

      // test if we hit anything
      PhysHit phys_hit;
      if( Physics.ray(pos, dir*D.viewRange(), &phys_hit) )
      {
          // Clicked on something, but what???
      }
      else
      {
         // Clicked on 'nothing'
      }

Now I want to check if I clicked on the on the World Part mesh or not.
Later on I will also need to know which object I clicked on if any.

Any suggestions?
(This post was last modified: 05-24-2015 07:44 PM by rstralberg.)
05-24-2015 07:43 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Silver Supporter

Post: #2
RE: Raycast - What did I click on?
Code:
AG_DEFAULT=0, // default group for all actors

   // user defined groups should be in the range of 1..15

   AG_DOOR      =29, // Game::Door
   AG_CONTROLLER=30, // Controller
   AG_TERRAIN   =31, // Game::World Terrain
   AG_NUM       =32, // number of actor groups
phys_hit.group()
Uses IndexToFlag(AG_TERRAIN)
if you want to specifically target only a certain group of objects

Then there is object type
phys_hit.obj->type()

Then you got the cast.
PhysHit phys_hit;
if(NPC *npc = CAST(NPC, phys_hit.obj)){
//object is of NPC
}
(This post was last modified: 05-24-2015 08:40 PM by Zervox.)
05-24-2015 08:37 PM
Find all posts by this user Quote this message in a reply
rstralberg Offline
Member

Post: #3
RE: Raycast - What did I click on?
Thanks. Will have a test tomorrow evening. Time for bed here
05-24-2015 08:44 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply