Raised This Month: $ Target: $400
 0% 

Solved [TF2] Is target in view field of player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
oplkill
Member
Join Date: Aug 2015
Old 04-27-2017 , 05:52   [TF2] Is target in view field of player
Reply With Quote #1

How to know, is player2 in view field of player1 ?

I tried to get angle from 2 view vectors: Player1_View_vector and View_vector_From_Player1_to_Player2. But failed, what i doing wrong?

in some code i executing: if(EntityInViewPlayer(client, target, 90.0))

Code:
stock void GetAngleVectorToTarget(any:client, any:target, Float:angles[3])
{
	new Float:clientEyes[3], Float:targetEyes[3], Float:resultant[3]; 
    GetClientEyePosition(client, clientEyes);
    if(target > 0 && target <= MaxClients && IsClientInGame(target)){
    GetClientEyePosition(target, targetEyes);
    }else{
    GetEntPropVector(target, Prop_Send, "m_vecOrigin", targetEyes);
    }
    MakeVectorFromPoints(targetEyes, clientEyes, resultant); 
    GetVectorAngles(resultant, angles); 
    if(angles[0] >= 270){ 
        angles[0] -= 270; 
        angles[0] = (90-angles[0]); 
    }else{ 
        if(angles[0] <= 90){ 
            angles[0] *= -1; 
        } 
    } 
    angles[1] -= 180; 
}

stock bool:EntityInViewPlayer(any:client, any:target, Float:maximumAngle)
{
	new Float:clientEyes[3], Float:clientEyesToTarget[3];
	new Float:angle1[3], Float:angle2[3];
	new Float:angle;
	GetClientEyePosition(client, clientEyes);
	GetAngleVectorToTarget(client, target, clientEyesToTarget);
	
	GetVectorAngles(clientEyes, angle1);
	GetVectorAngles(clientEyesToTarget, angle2);
	
	angle = FloatMul(angle1[0], angle2[0]);
	angle = FloatAdd(angle, FloatMul(angle1[1], angle2[1]));
	angle = FloatAdd(angle, FloatMul(angle1[2], angle2[2]));
	
	angle = FloatDiv(angle, GetVectorLength(angle1, false));
	angle = FloatDiv(angle, GetVectorLength(angle2, false));
	
	angle = ArcCosine(angle);
	
	//radians to angles
	angle = FloatMul(angle, 57.2958);
	
	PrintToChatAll("%f < %f", angle, maximumAngle);
	if (angle < maximumAngle)
		return true;
	
	return false;
}

Last edited by oplkill; 04-29-2017 at 09:32.
oplkill is offline
infi
Member
Join Date: Sep 2013
Old 04-29-2017 , 05:51   Re: [TF2] Is target in view field of player
Reply With Quote #2

https://forums.alliedmods.net/showpo...11&postcount=4

This snippet is what I'm using right now.

he explains it very nicely and his snippet works perfectly
infi is offline
oplkill
Member
Join Date: Aug 2015
Old 04-29-2017 , 09:32   Re: [TF2] Is target in view field of player
Reply With Quote #3

Quote:
Originally Posted by infi View Post
https://forums.alliedmods.net/showpo...11&postcount=4

This snippet is what I'm using right now.

he explains it very nicely and his snippet works perfectly
Thanks!
oplkill is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode