Skip to main content
Fix typos in code
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
bool IsBFacingA(vec2 A, vec2 B, float bRotation, float tolerance)
{
    var BtoA = A - B;
    var dir = normalize(BtoA);
    var orientation = vec2(sin(bRotation), cos(bRotation));
    var facing = dot(dir, orientation);
    return facing >= tolerance;
}
bool IsBFacingTheSameDirectionAsA(float aRotation, float bRotation, float tolerance)
{
    var aOrientation = vec2(sin(aRotation), cos(aRotation));
    var bOrientation = vec2(sin(bRotation), cos(bRotation));
    var facing = dot(aOrientation , bOrientation );
    return facing >= tolerance;
}
bool IsBFacingA(vec2 A, vec2 B, float bRotation, float tolerance)
{
    var BtoA = A - B;
    var dir = normalize(BtoA);
    var orientation = vec2(sin(bRotation), cos(bRotation);
    var facing = dot(dir, orientation);
    return facing >= tolerance;
}
bool IsBFacingTheSameDirectionAsA(float aRotation, float bRotation, float tolerance)
{
    var aOrientation = vec2(sin(aRotation), cos(aRotation);
    var bOrientation = vec2(sin(bRotation), cos(bRotation);
    var facing = dot(aOrientation , bOrientation );
    return facing >= tolerance;
}
bool IsBFacingA(vec2 A, vec2 B, float bRotation, float tolerance)
{
    var BtoA = A - B;
    var dir = normalize(BtoA);
    var orientation = vec2(sin(bRotation), cos(bRotation));
    var facing = dot(dir, orientation);
    return facing >= tolerance;
}
bool IsBFacingTheSameDirectionAsA(float aRotation, float bRotation, float tolerance)
{
    var aOrientation = vec2(sin(aRotation), cos(aRotation));
    var bOrientation = vec2(sin(bRotation), cos(bRotation));
    var facing = dot(aOrientation , bOrientation );
    return facing >= tolerance;
}
added 48 characters in body
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31

Of course using 0 as a threshold for determining if B is facing A is a bit wrong here, as you are talking about a person. If you define that a person is facing the other when the orientation towards the other is in 90 degree range, you can just check if the facing value is more than 0.5, which probably gives better results. You can also define that a person is facing another only when they are exactly looking at the other, which then requires you to use a value very close to 1.

Of course using 0 is a bit wrong here, as you are talking about a person. If you define that a person is facing the other when the orientation towards the other is in 90 degree range, you can just check if the facing value is more than 0.5, which probably gives better results. You can also define that a person is facing another only when they are exactly looking at the other, which then requires you to use a value very close to 1.

Of course using 0 as a threshold for determining if B is facing A is a bit wrong here, as you are talking about a person. If you define that a person is facing the other when the orientation towards the other is in 90 degree range, you can just check if the facing value is more than 0.5, which probably gives better results. You can also define that a person is facing another only when they are exactly looking at the other, which then requires you to use a value very close to 1.

Add details
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31

Now youBut this still does not answer your question.

You can use thisall that information to determine if A and B are facing the same direction, by getting the orientation of both A and B and comparing them with the dot product. Like this:

And there you go, that is how you determine if A and B are facing the same direction.

Now you can use this to determine if A and B are facing the same direction, by getting the orientation of both A and B and comparing them with the dot product.

But this still does not answer your question.

You can use all that information to determine if A and B are facing the same direction, by getting the orientation of both A and B and comparing them with the dot product. Like this:

And there you go, that is how you determine if A and B are facing the same direction.

Add details
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading
deleted 16 characters in body
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading
added 386 characters in body
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading
added 163 characters in body
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading
added 77 characters in body
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading
added 77 characters in body
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading
added 51 characters in body
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading
added 51 characters in body
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading
edited body
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading
Source Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Loading