Underwater Movement

Posted By: Ruben

Underwater Movement - 07/04/15 07:49

My goal is to make it to where if the player goes underwater, the player should be able to move in whatever direction the camera is facing. I have the program set up now that if the player jumps into water (using a region called "water"), I can make certain things happen like changing fog_color to equal 2 (creating a blue underwater fog).

When the player is above water on ground in my program, the player can only move front, back, right, and left, in whatever direction the camera is facing along those dimensions. When the player jumps into water, I would like the player to move in whatever direction the camera is facing, even if that means up, down, diagonal up or down, along with front, back, right, and left. I take it this involves working with the z variable.

This is the code I have so far for this:

Code:
action player_code()
{
   ...

   if(fog_color == 0)
   {
      move_vec.x = key_w - key_s;
      move_vec.y = key_a - key_d;
   }
   if(fog_color == 2)
   {
      move_vec.x = key_w - key_s;
      move_vec.y = key_a - key_d;
   }

   ...
}



When the player is on ground (fog_color = 0), the movement works just fine along the x and y planes.

When the player is underwater (fog_color = 2), I would like the player's movement to go any direction that the camera is facing. So for example, if the player's camera is facing diagonal up, and the player holds down the w key, I would like the player to swim diagonal up. If the player were to press and hold the s key while its camera is facing diagonal up, I would like the player to swim in reverse diagonal down.

I take it I would have to manipulate the move_vec.z , my.pan, and camera.pan somehow under the "if(fog_color == 2)" condition above. I have tried my own methods of manipulating these values, but nothing has worked so far.

Anyone have an idea on how to make this kind of underwater movement that I just described possible?
Posted By: Superku

Re: Underwater Movement - 07/04/15 08:55

Either adapt the player's orientation to the camera's pan (and tilt) and use a relative speed vector (first speed argument in c_move) or use vec_rotate with camera.pan and as an absolute speed vector.
Posted By: Ruben

Re: Underwater Movement - 07/05/15 08:14

Thank you Superku. I set the player's pan and tilt equal to the camera's pan and tilt, and now the underwater movement works perfectly. :-)
© 2024 lite-C Forums