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.
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
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.
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.
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.
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.
Too right! Have that exact problem with mine! Might try adding another “water detection” collision sphere which is turned on when the player goes into a prone position offset to be above the character, with an overlap function set to loop through and detect a named water body (which has a name tag), or maybe on tick and prone - check for it there? Just a thought!