About Store Forum Documentation Contact



Post Reply 
Objects under cursor - AI : Game::Chr
Author Message
Ogniok Offline
Member

Post: #1
Objects under cursor - AI : Game::Chr
Hi!

I have struct AI in my game. It comes from Game::Chr. I want to do something when AI obj is under cursor. I use this code but it didn't work:

Code:
//Get object under cursor
         Game::Obj *objectUnderCursor;

         objectUnderCursor = NULL;
         Vec pos, dir;
         ScreenToPosDir(Vec2(0, 0), pos, dir);

         PhysHit phys_hit;
         if(Physics.ray(pos, dir * D.viewRange(), &phys_hit, ~IndexToFlag(AG_CONTROLLER))) objectUnderCursor = phys_hit.obj;

         //Detect type of object which player want to interact
         if(AI *interactObject = CAST(AI, objectUnderCursor))
                 {

                 }

Debugger show that objectUnderCursor is empty all the time.
04-11-2010 07:21 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Objects under cursor - AI : Game::Chr
~IndexToFlag -> IndexToFlag ?
04-11-2010 09:20 PM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #3
RE: Objects under cursor - AI : Game::Chr
I've changed to this:

Code:
if(Physics.ray(pos, dir * D.viewRange(), &phys_hit, ~IndexToFlag(AG_CONTROLLER))) objectUnderCursor = phys_hit.obj;

but then objectUnderCursor = Player
04-11-2010 09:29 PM
Find all posts by this user Quote this message in a reply
Xhizors Offline
Member

Post: #4
RE: Objects under cursor - AI : Game::Chr
Your current mouse position check is Vec2(0, 0) set it to Ms.pos and you will have more success.

Code:
Game::Obj *objectUnderCursor;

Vec screen_pos, screen_dir;
ScreenToPosDir(Ms.pos, screen_pos, screen_dir);

Vec start = screen_pos;
Vec end = screen_pos + screen_dir * D.viewRange();

PhysHit phys_hit;
if(Physics.ray( start, end - start, &phys_hit, ~IndexToFlag(AG_CONTROLLER)))
{
     objectUnderCursor = phys_hit.obj;
}
(This post was last modified: 04-13-2010 07:43 AM by Xhizors.)
04-13-2010 07:40 AM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #5
RE: Objects under cursor - AI : Game::Chr
I know that my mouse position is Vec2(0, 0) because this is crosshair in my game. Mouse isn't visible. I try your code but it didn't work.
(This post was last modified: 04-13-2010 06:17 PM by Ogniok.)
04-13-2010 05:24 PM
Find all posts by this user Quote this message in a reply
Xhizors Offline
Member

Post: #6
RE: Objects under cursor - AI : Game::Chr
(04-13-2010 05:24 PM)Ogniok Wrote:  I know that my mouse position is Vec2(0, 0) because this is crosshair in my game. Mouse isn't visible. I try your code but it didn't work.

If you run only:

if(Physics.ray( start, end - start, &phys_hit))

Do you get any valid object on phys_hit.obj ?
04-14-2010 07:27 AM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #7
RE: Objects under cursor - AI : Game::Chr
[Image: vzzx5xm.jpg]

----------------------------------------------------
5,000 post
(This post was last modified: 04-17-2010 11:16 AM by Ogniok.)
04-16-2010 02:29 PM
Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #8
RE: Objects under cursor - AI : Game::Chr
All interactions work but interaction with AI don't work.
Code:
if(Ms.b(0) && timeToAction <= 0)
      {
         //Get object under cursor
         Game::Obj *objectUnderCursor = NULL;

         Vec pos, dir;
         ScreenToPosDir(Vec2(0, 0), pos, dir);

         PhysHit phys_hit;
         if(Physics.ray(pos, dir * D.viewRange(), &phys_hit, IndexToFlag(AG_CONTROLLER))) objectUnderCursor = phys_hit.obj;

         //Detect type of object which player want to interact
         if(Tree *interactObject = CAST(Tree, objectUnderCursor)) //WORKS
         {
                         //tree interaction code - WORKS
         }//end if(Tree * interactObject = CAST...
         else if(AI *interactObject = CAST(AI, objectUnderCursor)) //DOESN'T WORK
         {
             //open dialogue with Character //DOESN'T WORK
         }
         else //WORKS
         {
            //attack code... //WORKS
         }//end else
      }//end if(Ms.b(0) && timeToAction <= 0)

Only interaction with AI don't work so problem is in AI class
(This post was last modified: 04-25-2010 03:52 PM by Barthap.)
04-25-2010 03:51 PM
Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #9
RE: Objects under cursor - AI : Game::Chr
I noticed Phys hits AI if it's died it's after call ragdollEnable() function in AI class.

If AI Died(ragdollEnable)
Phys works
Else
Don't work
(This post was last modified: 04-25-2010 06:59 PM by Barthap.)
04-25-2010 06:51 PM
Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #10
RE: Objects under cursor - AI : Game::Chr
The problem is resolved! In AI::Create() we added
Code:
T.ctrl.actor.group(31);
and it helped
05-01-2010 09:24 AM
Find all posts by this user Quote this message in a reply
spire8989 Offline
Member

Post: #11
RE: Objects under cursor - AI : Game::Chr
I've actually replicated your technique it seems and I have a:

if(Interactable *interactObject = CAST(Interactable, objectUnderCursor))

but it always returns false and breaks off there. Any ideas what might be wrong? Everything else is pretty much the same as yours.
05-10-2010 01:21 AM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #12
RE: Objects under cursor - AI : Game::Chr
Did you set mode of objects with OBJ_TYPE Interactable to default? And did you set container for this objects in game?
05-10-2010 09:45 AM
Find all posts by this user Quote this message in a reply
spire8989 Offline
Member

Post: #13
RE: Objects under cursor - AI : Game::Chr
Bah, every time I write something on here, I fix it myself.
(This post was last modified: 05-10-2010 09:25 PM by spire8989.)
05-10-2010 06:28 PM
Find all posts by this user Quote this message in a reply
Post Reply