Download

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.

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: