Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Finding if a player is facing the back of another.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 KnolanCross   Members   -  Reputation: 1333

Like
0Likes
Like

Posted 14 March 2013 - 08:23 AM

Hello there guys, I am creating a game based on arena matches, with RPG style fights. I want some abilities to be more poweful (or only usable) when you are facing the enemy's back.

Assuming I have two entities (player or AI controlled pet) and that I know their positions and looking angles, is there any direct way to find the if one is facing the back of the other?

 

Right now I am using a quadrant approach, for instance If I had two entities A and B and I wanted to know if A is on B's back.

 

1) I define which quadrant B is relatively to A (assuming A's position as the origin).

2) I add and subtact 45º from A's looking angle and find the quadrants of those resulting angles (I assume the front is 90º wide).

3) If B is on one of those quadrants and its looking angle is in the interval defined in the former step, then A is on B's back.

 

But I am wondering if there is a better approach?

 

Thanks in advance.


Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).


Sponsor:

#2 Ravnock   Members   -  Reputation: 289

Like
4Likes
Like

Posted 14 March 2013 - 08:38 AM

Hello there guys, I am creating a game based on arena matches, with RPG style fights. I want some abilities to be more poweful (or only usable) when you are facing the enemy's back.

Assuming I have two entities (player or AI controlled pet) and that I know their positions and looking angles, is there any direct way to find the if one is facing the back of the other?

 

Right now I am using a quadrant approach, for instance If I had two entities A and B and I wanted to know if A is on B's back.

 

1) I define which quadrant B is relatively to A (assuming A's position as the origin).

2) I add and subtact 45º from A's looking angle and find the quadrants of those resulting angles (I assume the front is 90º wide).

3) If B is on one of those quadrants and its looking angle is in the interval defined in the former step, then A is on B's back.

 

But I am wondering if there is a better approach?

 

Thanks in advance.

 

Using the dot product between the two front vectors (FrontA and FrontB) you are able to know if they are looking in the same direction, and it's quite fast

 

http://en.wikipedia.org/wiki/Dot_product

 

if dot(FrontA,FrontB) > 0 then the angle is between PI/2 and -PI/2 (A is looking in the same direction than B)

else if (dot(FrontA,FrontB) < 0) they are looking in the opposite direction

 

After that you should check the vector distance between B and A to know if A is behind B

 

dot( Bpos-Apos, FrontA) > 0 then A is behind B

 

If the signs are ok it should work...


Edited by Ravnock, 14 March 2013 - 08:39 AM.


#3 DrEvil   Members   -  Reputation: 1105

Like
0Likes
Like

Posted 14 March 2013 - 08:39 AM

You should be able to do such a check with a couple vector dot products. Take the view vector of each and dot them. If they are both positive the guys are facing a similar direction. Compare the value to the angle tolerance you wish to enforce. Also if you dot the victims forward vector with the vector to the attacker you can discover if the attacker is behind, as it will be negative, and again you can tweak the angle tolerance by comparing it to the angle tolerance you want to allow.

#4 KnolanCross   Members   -  Reputation: 1333

Like
0Likes
Like

Posted 14 March 2013 - 10:39 AM

Thanks a lot, I will try and see if it works.


Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS