Character Movement and Water

Hi,

**I have made a Island and it's surrounded by water and you can walk on water. How do you make it so your Character can swim in the water? Is there already Character Movement for swimming? If there is not how would I make the Character Movement for swimming? I placed a plane down and then added the Ocean Water texture to it. Is there a better way I could make a Ocean?**

Thanks for your Help! :slight_smile:

Hi TheCreativeGames,

Creating water is best done through physics volumes (you can find those among the other volumes in the leftmost bar of your editor). These volumes can be tweaked to simulate water physics and have a tickbox to make certain blueprint and C++ functions aware that they are water volumes.

You will need to implement some custom movement in water inside your Character, such as swimming upwards instead of jumping, or not sinking like a stone. This is fairly easy to do - I use this for simple upwards motion while holding the space bar in water:

//register swim up function
	InputComponent->BindAxis("SwimUp", this, &ACharacter::SwimUp);

void ACharacter::SwimUp(float Value)
    {
    	if (CharacterMovement->IsInWater()) //if the player is in water...
    	{
    		FRotator Rotation = Controller->GetControlRotation();
    		//limit pitch when walking, swimming or falling
    		if (CharacterMovement->IsMovingOnGround() || CharacterMovement->IsFalling() || CharacterMovement -> IsInWater())
    		{
    			Rotation.Pitch = 0.0f;
    		}
    		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Z);
    
    		//swim up
    		AddMovementInput(Direction, Value);
    	}
    }

I also suggest coupling it with a PostProcessingVolume that alters the light colour and adds gaussian blur to make the player aware that they have entered water :slight_smile:

Thanks So Much for your help! I am using Blueprints instead of C++. Could I possibly send you my game folder and you could do this for me in Blueprints? Or what would I do in the Blueprints could you tell me step by step? Thank You!

It shouldn’t be too hard to do this in Blueprints ^.=.^ The general gist is this:

  1. If the player presses his Space Bar…
  2. Check if he’s inside a water volume (a water volume is a physics volume with the “Water Volume” checkbox ticked)
  3. If he/she is, Get the control rotation (that’s the camera’s rotation)
  4. Set the pitch to 0 if the player is in water, falling or walking on the ground (to prevent the space bar from making you swim backwards instead of up)
  5. Get the Z vector from the rotation via a Rotation Matrix (this is the direction, up in this case)
  6. Add movement in that direction

I haven’t worked a lot with blueprints, so I’m not absolutely sure how to set this up, node-by-node - however, it should be relatively simple to just modify what you have ^.=.^

If you get stuck, you can add me on Skype (rumptrollet) and I’ll have a look.

RESOLVED

Wish you would have filled this out.
The water volumes and such aren’t too difficult but there seems to be a lack of setting up the controls very well.

I’m all blue print and mobile. So i was just going to set “forward” to same location camera is facing. Yet nothing I seem to try works. I STILL just move like I am flat on the ground