Cone area of effect
by D B · in Torque Game Engine · 04/08/2006 (2:46 pm) · 7 replies
I am currently making use of the RPGDialog resource, where pressing a button will start a dialogue with an NPC. However, it does this by getting a radius (and therefore, the player can talk to NPCs even when they are not facing them).
What I am trying to do is make it so that it gets a cone shape rather than a radius. I was thinking of getting the rotation vector (using getForwardVector()), and then 2 vectors from the left and right of it, and checking to see if the NPC is between those 2 vectors (bringing about the cone shape).
However, I am having some trouble with this; I am not sure how to get the 2 vectors on the sides, and then how to convert those two vectors into the area of effect.
Does anyone have any suggestions as to what I can do, or where I can look for this?
Thank you.
What I am trying to do is make it so that it gets a cone shape rather than a radius. I was thinking of getting the rotation vector (using getForwardVector()), and then 2 vectors from the left and right of it, and checking to see if the NPC is between those 2 vectors (bringing about the cone shape).
However, I am having some trouble with this; I am not sure how to get the 2 vectors on the sides, and then how to convert those two vectors into the area of effect.
Does anyone have any suggestions as to what I can do, or where I can look for this?
Thank you.
About the author
#2
When I said the player can talk to NPCs when they are not facing them, I meant the PLAYER is not facing the NPC. =P
04/08/2006 (3:28 pm)
Sorry, I just realized how unclear I was up top.When I said the player can talk to NPCs when they are not facing them, I meant the PLAYER is not facing the NPC. =P
#3
04/08/2006 (3:52 pm)
Were you looking for a script only solution, or a C++ one?
#4
how to use it...?
Well it's simple. GetAngle returns the angle between the players eye point, and the source object. It returns the amount of degrees between the two. That way you can decide how many degrees off you want the search to happen.
sorta how i use it.
04/08/2006 (3:57 pm)
Maybe this may help. I wrote this for my search function.function GetAngle(%sourceObj,%targetObj){
%eyeVec =VectorNormalize(%sourceObj.getEyeVector());
%toObjVec =VectorSub(%targetObj.getPosition(),%sourceObj.getPosition());
%dot =VectorDot(%eyeVec,VectorNormalize(%toObjVec));
%rad =mAcos(%dot);
return mRadToDeg(%rad);
}how to use it...?
Well it's simple. GetAngle returns the angle between the players eye point, and the source object. It returns the amount of degrees between the two. That way you can decide how many degrees off you want the search to happen.
........
%angle=getangle(%obj,%targetObject);
if (%angle<30){
%validTarget=%targetObject;
}
}
}
.....sorta how i use it.
#5
@Ramen: Ooh... that sounds like it could be just what I'm looking for! I will try implementing it. Thank you! :D
04/08/2006 (4:04 pm)
@Brandon: Either type of solution would be fine with me, though I am much more comfortable working with scripting than I am with the engine coding.@Ramen: Ooh... that sounds like it could be just what I'm looking for! I will try implementing it. Thank you! :D
#6
04/08/2006 (4:33 pm)
What about just checking if a NPC in the camera frustrum?
#7
@Alexander: I probably should have said this earlier, but I have been making use of the Advanced Camera resource, and I have my camera set up in God View Mode, and is set to 3rd person, so I don't think I would be able to do anything camera related. Thanks for the suggestion, though. =P
04/08/2006 (4:59 pm)
@Ramen: I got it working! Thank you so much for your help. :D@Alexander: I probably should have said this earlier, but I have been making use of the Advanced Camera resource, and I have my camera set up in God View Mode, and is set to 3rd person, so I don't think I would be able to do anything camera related. Thanks for the suggestion, though. =P
Torque 3D Owner Brandon Maness