[SOLVED] Simple Question - Angle around circle

Can someone point me to the type of math that is need to handle this.
image

I have two examples. Top left and lower right.

I have an enemy in red, its view direction is the black line. Then have the player in Blue, with their view direction being the black line.

I’ve done a dot product of the two directions to get the angle between the two people. But What I’m looking for also, to determine if I’m on their left side vs. right side.

I don’t know the math for that.

Adding the 2 vectors will give you a resultant vector, then subtract the resultant vector from your current position so position vector - resultant vector if the result is positive (bigger than zero) then the player is at the left (at the positive side) otherwise if the result is negative the player would be at the right side.

Another solution is comparing the angle between those two vectors with the polar representation of the position vector on a specific axis (I don’t know how to do this on 3d).

Dot product with their left vector. Positive 0…1 means they are on the left. Negative 0…1 means they are on the right. And the result is usually even suitable for plugging into steering algorithms.

left vector = obj.getRotation().mult(Vector3f.UNIT_X)
…at least in JME standard “look down Z axis” orientation.

1 Like

That was the solution. Now my Quad and display the correct angle of the pixel art of the person depending on the view angle of the player.

Example of camera being at different angles displaying the texture. There are 8 angles of each player and a player has a view direction shown by the white lines. White lines shows the area where they will pickup the enemy and go into attach mode.

Thank again.

1 Like

Actually. Something I’m missing. This only works when the enemy is at 0,0,0 with ViewDirection of (0,0,1).

Once they turn and the viewDirection changes, the calculation end up different all the time based on the viewDirection.

I assume that the two vectors for the dot product are:
normalized player direction
enemy relative to player

??

Edit: or replace “player” with “enemy” and vice versa depending on perspective.

To be 100% clear, given:

Game object: looker
Game object: target

Vector3f left = looker.getLocalRotation().mult(Vector3f.UNIT_X);
Vector3f targetRelative = target.getLocalTranslation().subtract(looker.getLocalTranslation());

// If we want to use it for steering input:
targetRelative.normalizeLocal();

float leftness = targetRelative.dot(left);

Thanks. That works 100% of the time. I see what I did wrong.