Page 1 of 1

Determining if a player is behind another player

Posted: Wed Aug 17, 2016 5:57 pm
by arawra
Would this do it?

Syntax: Select all

if abs((victim.view_angle + 360) - (attacker.view_angle + 360)) <= 90:


E:

Syntax: Select all

if abs((victim.view_angle[1] + 360) - (attacker.view_angle[1] + 360)) <= 90:

Re: Determining if a player is behind another player

Posted: Wed Aug 17, 2016 6:41 pm
by Ayuto
The attacker's view angle is not relevant for this calculation. However, I would do it completely without the view angle, but use the view vector.

Syntax: Select all

from events import Event
from players.entity import Player

# Our test bot/player
bot = Player(1)

@Event('player_say')
def player_say(event):
player = Player.from_userid(event['userid'])
print(point_is_behind_player(bot, player.origin))


def point_is_behind_player(player, point):
view_vec = player.view_vector
origin = player.origin

p1 = origin - view_vec
p2 = origin + view_vec
return point.get_distance_sqr(p1) < point.get_distance_sqr(p2)
Maybe you even want to calculate this on a 2D basis.

Re: Determining if a player is behind another player

Posted: Wed Aug 17, 2016 7:20 pm
by arawra
Maybe 'behind' another player wasn't the proper wording. Should have said if one player isn't looking at another.

Re: Determining if a player is behind another player

Posted: Wed Aug 17, 2016 7:31 pm
by D3CEPTION
how can you mix up those 2 different things? :D
i would raytrace the target players respective bones then

Re: Determining if a player is behind another player

Posted: Wed Aug 17, 2016 7:36 pm
by Ayuto
arawra wrote:Maybe 'behind' another player wasn't the proper wording. Should have said if one player isn't looking at another.

Well, that's what the function does. If point_is_behind_player() returns True, you know that the given player does not see the given point.

Re: Determining if a player is behind another player

Posted: Wed Aug 17, 2016 7:38 pm
by D3CEPTION
ayutos function is basically checking 180 degrees behind the player. if you additionally need to decrease the viewlimit to < 180 you want to add another viewangle check. if you want to simply see if you can view players you can raytrace them on the bones you want to check for..