Any help appreciated. Thank you in advance.
Modifié par GhostOfGod, 09 février 2011 - 04:49 .
Modifié par GhostOfGod, 09 février 2011 - 04:49 .
Modifié par GhostOfGod, 09 février 2011 - 05:45 .
Anyone writing might need to know a bit more info...
Such as,
(1) Does the facing of the Target matter.... do they have to be facing us also?
(2) Do we just need to just see the Target or is distance a factor?
(3) How wide in degrees is the cone we use for "facing the target" do we want it to change depending on distance to target?
(4) Anything I forgot to ask that the script needs to check for.
Modifié par CalSailX, 09 février 2011 - 06:16 .
Modifié par GhostOfGod, 09 février 2011 - 06:59 .
Modifié par Melkior_King, 09 février 2011 - 11:35 .
GhostOfGod wrote...
Just wondering if anyone has created a function to see if an object is facing a particular object or creature. I suck at math and cant quite get my head around a way to do it. I was thinking of using the vectors of the two objects in conjuction with the GetFacing function. You get the vector of the caller and then the vector of the object to check, figure out the +,- of the x and y and then check the get facing of the caller...something. I don't know.
Any help appreciated. Thank you in advance.
Modifié par Lightfoot8, 09 février 2011 - 05:38 .
Modifié par _six, 09 février 2011 - 09:41 .
//npc heartbeat
int GetIsFacingTarget(object oSelf, object oTarget, int nViewArc);
int GetIsFacingTarget(object oSelf, object oTarget, int nViewArc)
{
location lSelf = GetLocation(oSelf);
location lTarget = GetLocation(oTarget);
float AngleOffset = VectorToAngle( GetPosition(oTarget) - GetPosition(oSelf)) - GetFacing(oSelf) ;
//float fViewArc = 180.0;
return (abs(FloatToInt(AngleOffset)) < nViewArc/2);
}
void main()
{
object oSelf = OBJECT_SELF;
object oTarget = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
if (GetIsFacingTarget(oSelf, oTarget, 120))
{
SendMessageToPC(oTarget, "I see you.");
}
}