About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Raycast inconsistency.
Author Message
scotty1121 Offline
Member

Post: #1
Raycast inconsistency.
We are raycasting onto "npcs" in our game which is an actor to change mouse cursor types and behaviours. If you are close to the npc it doesn't cast correctly. but if you move away from it, it does. I have a video which shows clearly what happens:

http://www.youtube.com/watch?v=VFzdy9TNoaM

The code is as follows:

if(Ms.startPos() != Ms.pos()){T.obj =NULL;mst=MHand;
if(!Ms.hidden() || Gui.ms()==NULL)
{
Vec2 screen =(Ms.pos());
UInt actor_groups=~(IndexToFlag(AG_NPC));
Vec pos, dir; ScreenToPosDir(screen,pos,dir);
PhysHit phys_hit;
if(Physics.ray(pos, dir*D.viewRange(), &phys_hit, actor_groups))
{
T.obj =phys_hit.obj;
T.pos =phys_hit.plane.pos;
}
}
}
In NPC struct, if(Cur.obj == this)mst=MNpc;
Note mst is mouse types
(This post was last modified: 12-10-2012 05:24 PM by scotty1121.)
12-10-2012 05:24 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #2
RE: Raycast inconsistency.
In this line:
if(Physics.ray(pos, dir*D.viewRange(), &phys_hit, actor_groups))
dir looks like it's relative to pos. So maybe something like pos+dir*D.viewRange() could work?
12-10-2012 09:24 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Raycast inconsistency.
@scotty1121:
UInt actor_groups=~(IndexToFlag(AG_NPC));
specifies everything except NPC
please use debugging to investigate results of the raycasting

@Rubeus: no, actually the 2nd param is the delta, so the codes for that are ok from scotty1121
12-14-2012 01:27 PM
Find all posts by this user Quote this message in a reply
Post Reply