Pan/Tilt in relation to entity?

Posted By: Ruben

Pan/Tilt in relation to entity? - 05/20/18 23:27

I know that if I want to determine how much distance there is between the player and an entity, I can use the vec_dist() function, like this:

Code:
distanceDifference = vec_dist (player.x, otherEntity.x);

if(distanceDifference < 70)
{
   beep();
}



So in this case, if the distance in units between the player and the other entity is less than 70 units, the game starts beeping.

It is nice to know there is a function that lets us know the distance between two entities.

Is there a similar function allowing us to know how much the player is panned and/or tilted away from the other entity, to where if the player was pointed directly at the other entity, the number indicator would equal 0. If the player panned right or left away from that same entity, the pan number indicator would increase or decrease from 0. The same for if the player tilted up or down away from that same entity, the tilt number indicator would increase or decrease from 0?

So instead of measuring distance from the player to the entity, it would measure how much the player is panned or tilted away from the entity instead?

I think I might be able to use the vec_to_angle() function to do this, but I am trying to figure out how this would be done. Any help would be greatly appreciated. Thank you.
Posted By: txesmi

Re: Pan/Tilt in relation to entity? - 05/21/18 08:17

Look at http://www.conitec.net/beta/ang_diff.htm.
Posted By: Superku

Re: Pan/Tilt in relation to entity? - 05/21/18 09:30

Alternatively, you could use the dot product which should be faster and maybe even more intuitive to use in this case. Something like this:

Code:
VECTOR dir1,dir2;

vec_for_angle(dir1,player.pan);
vec_diff(dir2,otherEntity.x,player.x);
vec_normalize(dir1,1);
vec_normalize(dir2,1);

vec_dot(dir1,dir2) -> 1 if player is facing otherEntity,
                     -1 if player is facing in the exact opposite direction

Posted By: Ruben

Re: Pan/Tilt in relation to entity? - 05/23/18 15:12

Thank you Superku! Your idea seems to be working. Thank you again! And thank you txesmi as well. :-)
Posted By: Superku

Re: Pan/Tilt in relation to entity? - 05/23/18 18:59

You're welcome! Just something I've noticed looking at my post:

vec_for_angle(dir1,player.pan);

dir1 is already normalized (meaning to length 1), so you can drop the vec_normalize(dir1,1) instruction.
Posted By: Ruben

Re: Pan/Tilt in relation to entity? - 05/25/18 01:39

Thank you Superku. :-)
© 2024 lite-C Forums