I have code that allows the camera to glide along walls and other objects when the player's back is pointing up close to them, causing the camera to come closer to the player's back of head, as the camera glides along the wall or other object as the player rotates.

This camera code works fine when the player is above water and standing vertically and walking upright. The problem happens when the player jumps into water, its animation goes from walking to swimming where its body tilts forward (so that its body is now horizontal instead of vertical), and its bounding box changes so that it is in line with its now horizontal swimming body. When in the underwater swimming state, the camera does not glide along walls when the player rotates its back facing the wall while swimming. The camera just does not go through, which prevents the player from rotating near a wall.

Here is my code in making this all happen:

Code:
action actCameraCollider () 
{
   proc_mode = PROC_LATE;
   wait(1);
   my->flags |= INVISIBLE | PASSABLE; 
   my->eflags = FAT | NARROW;
   vec_set(&my->max_x, vector(8, 8, 8));
   vec_set(&my->min_x, vector(-8, -8, -8));
   vec_set(&my->skOriginX, vector(0, -7, 50)); // NEW
	
   vec_set(&my->skOffsetX, vector(0, -25, 40)); // NEW
   my->skDistance = 80; // NEW
   my->skDistSoft = my->skDistance;
   my->parent = player;
   while (my->parent == player) 
   {
      my->skDistance = clamp(my->skDistance + mickey.z * 0.3, 20,
         400);
      camera->pan = player->pan;
      camera->tilt = clamp(camera->tilt - mickey.y * 0.2, -90, 90); 
      vec_set(&my->pan, &player->pan);
      vec_set(&my->x, &my->skOriginX);
      vec_rotate(&my->x, &player->pan);
      vec_add(&my->x, &player->x);
      vec_set(&my->skCenterX, &my->skOffsetX);
      vec_rotate(&my->skCenterX, &player->pan);
      vec_add(&my->skCenterX, &player->x);
      vec_for_angle(&my->skDirX, &camera->pan);
      vec_scale(&my->skDirX, -my->skDistance);
      vec_set(&my->skTargetX, &my->skCenterX);
      vec_add(&my->skTargetX, &my->skDirX);
      you = player;
      var nDist = c_trace(&my->x, &my->skTargetX, IGNORE_YOU |
         IGNORE_PASSABLE | USE_BOX);
      if (nDist > 0)
         my->skDistSoft += (nDist - my->skDistSoft) * time_step * 2;
      else
         my->skDistSoft += (my->skDistance - my->skDistSoft) *
            time_step * 2;
      vec_diff(&my->skDirX, &my->skTargetX, &my->x);
      vec_normalize(&my->skDirX, my->skDistSoft);
      vec_set(&camera->x, &my->x);
      vec_add(&camera->x, &my->skDirX);
      wait(1);
   }
   ent_remove(me);
}

action player_code()
{
   goToTheBeginning:

   ...

   ent_create(NULL, &my->x, actCameraCollider); 
   wait(1); 

   ...

   // BOUNDING BOX FOR PLAYER OUT OF THE WATER, STANDING UPRIGHT.
   vec_set(&my->max_x, vector(2, 23, 50.5));
   vec_set(&my->min_x, vector(-2, -23, 0));

   ...

   while (player_health > 0)
   {
      // IF PLAYER JUMPS INTO WATER, FROM OUT OF THE WATER.
      if((water_mode == 0) && (inTheWater == 1)) 
      {
         // RESETS COLLISION BOX
         vec_set(&my->max_x, vector(0, 0, 0));
	 vec_set(&my->min_x, vector(0, 0, 0));

         // JUMPS TO BEGINNING OF THIS FUNCTION.
	 goto goToTheBeginning;
      }
		
      if((water_mode == 1) || (water_mode == 2) || (water_mode == 3))
         // IF PLAYER IS INSIDE WATER
      {
         // COLLISION BOX CHANGES TO MATCH PLAYER'S HORIZONTALLY
         //    SWIMMING BODY, HOWEVER, CAMERA IS NOT GLIDING ON
         //    WALLS WHEN PLAYER TURNS ITS FEET FACING THE WALL
         //    WHILE SWIMMING.
         vec_set(&my->max_x, vector(53, 2, 40)); 
	 vec_set(&my->min_x, vector(-23, -2, 30));
			
	 inTheWater = 1;
      }

      ...

   }
}



So basically, the "camera gliding along the walls while the player turns its back to them while rotating" works when the player is out in the air, but once the player jumps in water and starts swimming around, it does not work anymore. The camera will not glide, causing the player to not be able to rotate near a wall.

Does anyone have a clue on how to make this camera function work for being underwater as well?


Edited by Ruben (06/19/18 10:05)