I am trying to make it so that if the player moves near a wall, and turns its back toward it while turning its body, the camera following the player will glide along the inside of the wall, pushing itself closer to the player's back, and then backs up to its normal following distance once the player's back is turned away from the wall.

I have a function that mostly does this. However, for some reason, while the player is turning its body while facing its front away from the wall (back toward wall), the camera will go behind the wall for the first 90 degrees on the left side of the turn instead of gliding on the inside of the wall, staying at the same distance behind the player as it would have with no collision detected, but then for the second 90 degrees of the turn on the right, the camera will start doing what I want it to do by gliding on the inside of the wall coming closer to the player's back for the remainder of the turn. It is always the first 90 degrees on the left side of the turn where the camera goes through the wall behind the player (what I do NOT want to happen), and always the second 90 degrees on the right of that same turn where the camera does not go through the wall and instead glides on the inside of the wall (what I would like to happen for the whole 180 degrees of this turn). This happens in the exact same manner from left to right, no matter what the wall, no matter where the wall is.

Here is my camera function:

Code:
void _handle_cam_3rdperson()
{
   c_rotate ( me, vector(-mickey.x * 0.3, 0, 0), IGNORE_ME |
              IGNORE_PASSABLE | IGNORE_SPRITES | USE_POLYGON |
              GLIDE );
		
   my.skNextPan = my.pan;
	
   my.skNextTilt = clamp ( my.skNextTilt - mickey.y * 0.3, 
                              -90, 90 );
   my.skNextRoll = 0; 
	
   VECTOR vecOrigin;	
			
   vec_set ( vecOrigin, vector(5,-25,40) ); 
   vec_rotate ( vecOrigin, vector(my.pan,0,0) ); 
   vec_add ( vecOrigin, my.x ); 	

   VECTOR vecTarget;
   vec_for_angle ( vecTarget, my.skNextPan );
	
   vec_scale ( vecTarget, -80 );
	
   vec_add ( vecTarget, vecOrigin );

   // THIS SEEMS TO BE WHERE THE ERROR LIES		
   var distance = c_trace ( vecOrigin, vecTarget, IGNORE_ME |
                            IGNORE_PASSABLE | IGNORE_SPRITES |
                            USE_POLYGON ); 
	
   if ( HIT_TARGET )
   {
      beep(); // THIS BEEPS DURING THE 2ND 90 DEGREES OF THE TURN IN
              //    QUESTION, NOT DURING THE 1ST 90 DEGREES.

      vec_set ( vecTarget, hit.x );
		
      if ( distance > 0 )
         reset ( me, TRANSLUCENT );
      else
         set ( me, TRANSLUCENT );
   
   }
   else
   {
      reset ( me, TRANSLUCENT );
   }
		
   vec_lerp ( camera.x, camera.x, vecTarget, time_step );
		
   vec_sub ( vecOrigin, camera.x );
   vec_to_angle ( camera.pan, vecOrigin );
}


It appears that this line of code is causing the error in question:

Code:
var distance = c_trace ( vecOrigin, vecTarget, IGNORE_ME |
                         IGNORE_PASSABLE | IGNORE_SPRITES |
                         USE_POLYGON );


The beep() right after the HIT_TARGET beeps like crazy during the 2nd 90 degrees of the turn sensing the collision, but does not beep at all during the 1st 90 degrees of the turn which shows that collision is not being detected. Why is the c_trace line from vecOrigin and vecTarget not being detected during the first 90 degrees of the turn, but is being detected during the second 90 degrees of the same turn?

Any help will be greatly appreciated. Thank you.

Last edited by Ruben; 02/16/18 03:31.