Raised This Month: $32 Target: $400
 8% 

Solved in_view_cone of entity


Post New Thread Reply   
 
Thread Tools Display Modes
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-03-2020 , 13:01   Re: in_view_cone of entity
Reply With Quote #11

Dot product is probably what you are looking for.

First you need to find the direction vector pointing to the player. This can be done by subtracting the two origins and normalizing the resulting vector.

Code:
#include <engine> #include <xs>

Code:
new Float:entity_pos[3] entity_get_vector(entity_id, EV_VEC_pos, entity_pos) new Float:player_pos[3] entity_get_vector(player_id, EV_VEC_pos, player_pos) new Float:dir[3] xs_vec_sub(player_pos, entity_pos, dir) xs_vec_normalize(dir, dir)

Now you need to find the entity's facing direction vector. To do this, simply convert its angle to a vector and normalize it.

Code:
new Float:entity_angles[3] entity_get_vector(entity_id, EV_VEC_angles, entity_angles) new Float:facing_dir[3] angle_vector(entity_angles, ANGLEVECTOR_FORWARD, facing_dir) xs_vec_normalize(facing_dir, facing_dir)

Finally, compute the dot product. When working with normalized vectors (unit vectors / vectors of length 1), the result of dot product will always be between -1 and 1. If the result is greater than 0, it means that the entity sees the player.

Code:
new Float:dot = xs_vec_dot(dir, facing_dir) if (dot > 0) {     // something }

Note that the higher the result, the closer the player is to the center of the entity's field of view.

This method doesn't check obstacles. If you need that functionality, you can implement it using traceline.
__________________








CrazY. is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-03-2020 , 13:18   Re: in_view_cone of entity
Reply With Quote #12



Code:
Is running? 0
Is Celena Luna visible to ent 563? 0
Is Celena Luna in ent 563's viewcone? 0
Is wall between ent 563 origin and Celena Luna? 0
Is Celena Luna in ent 563 field of views? 0.99
It is work! Thank you @CrazY.
But then I found a problem the in process...


Somehow this part did dectect when there obvious object in front of it. Is wall between shown there aint any wall that that part

Edit: It seem to work normally now. Thank you so much~
__________________
My plugin:

Last edited by Celena Luna; 07-03-2020 at 14:01.
Celena Luna is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-03-2020 , 14:02   Re: in_view_cone of entity
Reply With Quote #13

The problem lies in the is_wall_between_points function. You want to pass the entity index rather than 0. Also, compare TR_flFraction value instead of the distance. If the value of TR_flFraction is less than 1.0, it means there is an obstacle between the two points; so return true, otherwise return false.
__________________









Last edited by CrazY.; 07-03-2020 at 15:01.
CrazY. is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-03-2020 , 14:46   Re: in_view_cone of entity
Reply With Quote #14

Quote:
Originally Posted by CrazY. View Post
The problem lies in the is_wall_between_points function. You want to pass the entity index rather than 0. Also, compare TR_flFraction value instead of the distance. If the value of TR_flFraction is less than 1.0, it means there is an obstacle between the two points; so return false, otherwise return true.
OMG, it does work.

Just gonna leave the stock here if someone need it
PHP Code:
stock is_wall_between_points(Float:start[3], Float:end[3], ignore_ent)
{
    static 
ptr
    ptr 
create_tr2()

    
engfunc(EngFunc_TraceLinestartendIGNORE_MONSTERSignore_entptr)
    
    static 
Float:flFraction
    get_tr2
(ptrTR_flFractionflFraction)

    
free_tr2(ptr)
    if(
flFraction 1.0)
        return 
true
    
else 
        return 
false    
    
//return floatround(get_distance_f(end, EndPos))

__________________
My plugin:

Last edited by Celena Luna; 07-03-2020 at 15:08.
Celena Luna is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-03-2020 , 15:03   Re: in_view_cone of entity
Reply With Quote #15

Actually it should be the inverse of what I told. If there's an obstacle it should return true, otherwise false.
__________________








CrazY. is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-03-2020 , 15:41   Re: in_view_cone of entity
Reply With Quote #16

Fixed
__________________
My plugin:
Celena Luna is offline
Reply


Thread Tools
Display Modes

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 07:54.


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