Roblox has terrain water which allows for Swimming on touch of the water. I would like to do the same using a part. I’ve seen many responses from people saying to set the humanoid state to Swimming, and use BodyMovers. However, how would I use a bodymover to move the player‘s character and which bodymover should I use?
You can also make a swimming animation and make the body run that animation when touching that part + moving.
e.g. when Idle you can disable the swimming and make a floating animation.
But what about the navigation in 3D space. Do you happen to know about how I can use body movers to move my character as if he was flying / swimming?
I never attempted anything like this but yes I figure you would simply set the humanoid state.
As I stated I never tried anything like this but I would assume that you would use bodygyro & bodyvelocity.
I recently adapted the math found in the artemis bow to a swimming ability for my game. I can see about putting it up after work if you’d like (eta 8 hours).
The only thing you’d need to change is the detection function for when you’re in water. I imagine you could use Region3 for this and check through a table of regions generated on the client from a list of water parts for if your rootpart is within the region. Might not be very performant if you have many water parts though.
It also currently doesn’t support sitting at the surface of the water. You’ll flip between the swimming and not swimming states.
Since I do plan to release this code in a megathread of Ability Nuggets™ eventually, I’m just providing the code as a rbxm file instead of uploading to the website. There are still a couple of issues with this code that I need to fix (walking animations overlay when you start swimming near the floor, performance & optimization, controller/mobile support, swimming near the surface, etc), but maybe you can work with it in its current state.
To fit your requirements you’ll need to change the function that determines when you’re in a body of water:
Swim.rbxm (3.9 KB)
What’s the concept that I should be implementing? Am I supposed to make the player overcome to force of gravity? Also how would I make the player move in the direction of the camera?
Pretty sure BodyMovers aren’t affected by gravity, and to get the player to move in the direction of the camera, just use lookVector
The wiki: Documentation - Roblox Creator Hub says:
Objects that inherit from the BodyMovers structure are used to move Parts against
gravity
Also, thanks for suggesting about LookVector. I was wondering about how people would do such a thing.
Does anyone know what is the most efficient way of changing the state of the humanoid? To change the state of a humanoid, a local script is required. Since I’m making a swimming script, I only want to fire :ChangeState
when the client touches a part. So how should I go about doing it?
Should I replicate the local script into the client and use a remote event to fire when needed?