Swimming on the water's surface

Hey all, so I’ve implemented swimming in my game and it was shockingly easy.

My one question however, is how do you get the character to lock to the water’s surface when you get to the top? I see it in so many games, but I haven’t the foggiest how it’s implemented.


Simple idea:

  • check if character is in water volume (or any volume that you can create on top of water)
  • in that volume add tag that says for eg: “water 260”
  • in character blueprint read tags from volume, you parse number and you know its 260 units high.
  • lock character to that value (or make some “sticky” area that does not let your character leave for second or two.

Neat & convincing!

Thanks Narwot, that’s definitely an interesting idea. So the difficulty is that if you enter the water volume, you go into “Swimming mode” which I want, because it gives it a true feeling of being able to dive into the water. I want it to lock the player to the surface when you get to the top of the volume, so the issue is how do I register when the player is at the top of the volume. Right now, as soon as you breach the top of the water even a bit, the game registers this as an “End overlap” but in my mind, it’s not ended yet because the player’s lower half is still in the water. I wonder if there’s a “Fully end overlap” rather than a “Start to end overlap” which is how the end overlap seems to behave.

Also, when it comes to locking the player to the surface, or as you suggest, locking them to a specific world height, I’m not sure how I would accomplish that. I’d have to somehow disable the physics simulation that they get when they’re in the water… disable gravity or what have you… also as it’s first person, I’d want them to be able to move in all axis along the water surface, but not be able to dive. I don’t know… I can’t even begin to imagine the logic behind this to start figuring out the code for it. But it has to be achievable since so many games have this functionality.

Also thanks Everynone. Glad you like how it’s looking so far :slight_smile:

Add a sphere collision at chest height. When that overlaps the water volume, they are in swimmable water (set swimming). After a dive, when they reach the top (surface), disable dive/down movement input, jump, and limit mouse pitch/yaw (rotation) to a set amount of degrees until the collision ends overlap.

1 Like

Hmmm… I see what you’re thinking… not sure if this will get the results I’m looking for, but it’s definitely in the right direction. I’m now picturing the swimming on the surface where the charter’s top half of the body is permanently out of the water which isn’t quite what I had in mind, but it definitely gets me thinking. My concern is that when you’re in swimming mode, gravity is pulling you down still, so how do you prevent that? Maybe I need to disable gravity at that point? I’ll play around with it for sure.

When you get to the surface and aren’t moving you’re treading. Once you apply movement you go into a swimming animation. Basically toggling blend spaces.

Oh and under character movement: swimming, there should be a buoyancy setting. You can adjust this at runtime. So when the character reaches the surface (collision end overlap) you can increase buoyancy. If they input dive, decrease, then apply movement. etc & so forth.

Oh nice, I didn’t realize you could adjust the buoyancy. That will most definitely help! Thanks for the tip :slight_smile:

I’m a bit late but in the volume select physics on contact. That way if your even just touching it you’ll be swimming.

This isn’t applicable in all instances of water volume interaction. For example if you’re less than chest deep. Say waist or ankle deep. Don’t want to be in a swimming state in those situations.

Poor guy trying to swim in a puddle.

1 Like

Very true, good point!

Generally you’ll add a sphere collision component to the character class, positioned at the chest. You’d use this to help in the determination of whether you should be swimming or not. Gets tricky/complicated when you have prone states allowing you to crawl into a water volume. Say like a beach scene.

Is there any tutorial on how to make this? As I’m a beginner unreal developer. And have no idea were to start. Need help!

To anyone still wondering easily swim on surface by doing this:
Create an actor with collision and buoyancy, add it as a child actor to your character, and update it’s XY location to match the character’s location. Then, when want to swim on the surface, make character lerp it’s Z coordinate to the child actor.