player.pan issue

Posted By: DLively

player.pan issue - 08/09/15 22:41

When I turn my players pan to the left, his pan is positive, (0 -> 360) if I turn to the right, his pan becomes negative (0 -> -360)

This is problem-some because I'd like to use the players pan as a trigger for particular moments, but if the player turns right a few times, his pan can become negative and thus wouldn't activate something like this

if(player.pan > 45 || player.pan < 270)...

How can I keep the players pan from going into the negatives?

I've tried player.pan %= 360;
player.pan = clamp(player.pan, 0, 360);// this only allows for left panning

Im not to sure what to do to overcome this. can someone please help me?
Posted By: Reconnoiter

Re: player.pan issue - 08/10/15 10:00

Should work:

player.pan = ang(player.pan);
if (player.pan < 0) player.pan += 360;
Posted By: txesmi

Re: player.pan issue - 08/10/15 12:12

I would recomend always using the -180<>180 range returned from ang instruction so you can take advantaje of the symmetry of the sign.

Code:
if ( abs(angle) < 45 )
   // front
else if ( abs(angle) > 135 )
   // back
else if ( angle > 0 )
   // left
else
   // right



Anyway cycle(angle,0,360); does the job.
Salud!
© 2024 lite-C Forums