Making a custom swimming system

Hi, I would like to make my own custom swimming system for my 3D platformer typed game. I have looked into a few examples and the one I wish to replicate the most was this one.

However, the only thing I could manage to figure out is checking if your camera is in a certain region to change to underwater atmosphere, beside that, I can’t seem to know how to make it possible to make your character go underwater and swim there. If anybody can help me then that would be great!

2 Likes

I’m not 100% sure if raycasts work properly with skinned meshes. If they do, I’d use a raycast from above the character to the characters position to see if it hits the water mesh. That way, you know the character is under the water.

I’d use the physics system to make the character move. Probably by adding an upwards force to cancel out gravity and then use physics constraints like VectorForce to get it to move around. If you use ContextActionService to overwrite the default controls then they shouldn’t interfere too much. The Humanoid has some weird ways that it affects charcters, they aren’t fully controlled by “sensible” physics. You could temporarily disable that by making the character fall, don’t remember how but you can search around.

Hope this helps, it’s a pretty open ended question so feel free to ask follow up questions if there are other, more specific things you’d like help with.

1 Like

In the video I just see that the animation when swiming is changed, so only change the animation used in Animate script.
Then the underwater checking could be done by reading voxels which works with default water, I tried before reading when player’s head is underwater by reading the voxel at the top of head and works great