I have a player who is just fine when it walks on land. When the player jumps into water and swims to the bottom, and then touches the floor or tilts up to look toward the top of the pool (while still being at the bottom), the camera view starts spinning wildly fast. If I tilt very slowly, I can see the spinning gradually (instead of immediately) get faster the more I tilt up. Sometimes the camera view will spin wildly just from merely touching the bottom.

The same thing happens if the player is swimming underneath an underwater ceiling (ceiling that is submerged). If the player tilts down to look at the ground while being directly underneath and close to the underwater ceiling, the camera and player will start spinning. If the player tilts down slowly from this position, again, it will gradually (rather than immediately) spin faster the more the player tilts downward.

I take it that the camera has to do with why it spins. Here is my camera code:

Code:
#define MC_CAMERA_ORIGIN_OFFSET    vector(5,-25,40)

...

void _handle_cam_3rdperson()
{
   var i; 
   VECTOR vec_temp;

   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, MC_CAMERA_ORIGIN_OFFSET ); 
   vec_rotate ( vecOrigin, vector(my.pan,0,0) ); 
   vec_add ( vecOrigin, my.x ); 	

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

   var distance = c_trace ( player.x, vecTarget, IGNORE_ME |
      IGNORE_PASSABLE | IGNORE_SPRITES | USE_POLYGON ); 
	
   if ( HIT_TARGET )
   {
      beep(); // THIS BEEPS WHILE THE CAMERA VIEW SPINS WILDLY, 
              //    BUT DOES NOT BEEP BEFORE.
	
      vec_set ( vecTarget, hit.x ); 

      vec_set ( vec_temp, hit.nx); 
      vec_normalize ( vec_temp, 11); 
      vec_add ( vecTarget, vec_temp); 
		
      if ( distance > MC_CAMERA_TRANS_TOLERANCE )
         reset ( me, TRANSLUCENT );
      else
         set ( me, TRANSLUCENT );
   }
   else
   {
      reset ( me, TRANSLUCENT );
   }
	
   vec_set(camera.x, vecTarget);
		
   vec_sub ( vecOrigin, camera.x ); 
   vec_to_angle ( camera.pan, vecOrigin ); // IF I COMMENT THIS 
      //    LINE OF CODE OUT, THE SPINNING STOPS, BUT I CANNOT
      //    TURN ANYWHERE WHILE SWIMMING UNDERWATER.
}



As I mentioned above, if I comment out the last piece of code [vec_to_angle() call], the spinning stops, but I cannot turn the player anywhere left to right, can only go straight. Does anyone have an idea on how to keep the camera and player from spinning wildly when it touches the ground or ceiling, while the player swims underwater, and still being able to turn left and right as needed rather than a fixed straight direction?

Last edited by Ruben; 05/02/18 06:24.