Determining if a player is behind another player

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Determining if a player is behind another player

Postby arawra » Wed Aug 17, 2016 5:57 pm

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:
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Determining if a player is behind another player

Postby Ayuto » Wed Aug 17, 2016 6:41 pm

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.
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Re: Determining if a player is behind another player

Postby arawra » Wed Aug 17, 2016 7:20 pm

Maybe 'behind' another player wasn't the proper wording. Should have said if one player isn't looking at another.
User avatar
D3CEPTION
Senior Member
Posts: 129
Joined: Tue Jan 26, 2016 1:24 pm
Location: Switzerland

Re: Determining if a player is behind another player

Postby D3CEPTION » Wed Aug 17, 2016 7:31 pm

how can you mix up those 2 different things? :D
i would raytrace the target players respective bones then
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Determining if a player is behind another player

Postby Ayuto » Wed Aug 17, 2016 7:36 pm

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.
User avatar
D3CEPTION
Senior Member
Posts: 129
Joined: Tue Jan 26, 2016 1:24 pm
Location: Switzerland

Re: Determining if a player is behind another player

Postby D3CEPTION » Wed Aug 17, 2016 7:38 pm

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..

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 33 guests