Hey guys! I'm here with my first question ever. After looking through page after page on google and discussing this with a few other developers, I decided I needed to hear from a broader group who might have more experience in this matter. I am asking this question because I cannot create my own character/humanoid and associated functionalities (at this time, and I'd rather not in the future), so please don't list that as a solution.
Because I don't want to fall into the trap of asking for help with my attempted solution and missing a potentially better solution, I'll start with my issue and then list the stuff I've tried. Right now, I'm trying to create a custom swimming framework that functions within certain y values on the plane. For instance, if the player's position vector has a y value that is, say, less than
0 and greater than
-25, then that player would be able to swim. This is a project for someone else, so don't tell me that I need to use Roblox's water (anyway, this causes less lag on the large scale I'm working with).
Initially, I tried using a
BodyGyro, but when that didn't work out, I moved on to manually setting the
CFrame of the
HumanoidRootPart. Basically, I make it so that the player, head to toe, points in the direction the camera is looking like an arrow. Right now, this works like a charm, but it doesn't. You see, for some annoying reason, Roblox decided that the
Humanoid should always be upright. This meant that I needed to modify the
CFrame on the
RenderStepped event of the
RunService. While this worked, it was really glitchy and constantly dragged me to the surface of the water by the force of the glitches. This is my basic problem, and I'd love any suggestions you guys have on how to fix it.
After discussing this with another developer, he suggested the
PlatformStand property be set to
true. And it worked! At least, it seemed to work until I realized that when I stopped swimming, my momentum carried me onward for what seemed like an indefinite amount of time. Not only that, but when I swam into a wall or solid object, my character immediately spun out of control and would not stop moving in seemingly random contortions for, again, what seemed like an indefinite amount of time. Now, I know why this is happening in theory, but I don't know in a way that can help me fix it, nor do I know a different way, other than
PlatformStand, to cease the glitchy resetting of the
Here are the relevant bits of my code: ```lua -- some irrelevant code before this connection = run_service.RenderStepped:Connect(function() if input_going then
local direction = camera.CFrame.LookVector local position = root_part.Position root_part.CFrame = CFrame.new( position, position + direction )*CFrame.Angles(math.pi/2, math.pi, math.pi) body_velocity.Velocity = camera.CFrame.LookVector*30 else body_velocity:Destroy() connection:Disconnect() local direction = camera.CFrame.LookVector local position = root_part.Position root_part.CFrame = CFrame.new(position)*CFrame.Angles(0, math.atan2(-direction.X, -direction.Z), 0) if is_swimming then body_position.MaxForce = Vector3.new(0, 7250, 0) body_position.D = 3000 end end
-- and later on:
while true do -- note that this loop does not loop very quickly for efficiency's sake.
local pos = root_part.Position local y_pos = pos.Y if y_pos > base_height and y_pos < top_height then if not is_swimming then if not created then body_position = Instance.new("BodyPosition") body_position.Parent = root_part body_position.MaxForce = Vector3.new(0, 7250, 0) body_position.D = 3000 created = true end humanoid.WalkSpeed = 0 humanoid.PlatformStand = true
-- and there is more code here, but it's unimportant -- just know that everything is reset to defaults when the player is outside of the water ```
In conclusion, I'd just like to restate my problem for clarity:
I'm working with a swimming framework and whenever I try to set the orientation of the
HumanoidRootPart to make the player upside down, sideways or something odd, it tries to reset it. I've managed to correct this via
RenderStepped, which I probably would have used anyway so that the player's character is always pointing the right direction, but this current solution is very glitchy due to Roblox constantly trying to reset the orientation.
PlatformStand is an option, but I don't know how I'd use it with all the downsides it has. Basically, I'm looking for a way to fix the downsides of
PlatformStand or to remove the constant
HumanoidRootPart orientation auto-correction (if it can be called correction).
If you would like to test the place with the
PlatformStand feature on (or off) to see what exactly is happening, leave a comment below and I'll make the appropriate changes (cause I'm testing a variety of things), and post a link. If you have any additional questions, feel free to post those below as well.
Turns out that no super ideal solution worked. I did, however, solve the issue. While a
BodyGyro did not work in the place of modifying the cframe of the root part, I found that if I used the platform stand property, modified the cframe of the root part, and then set the body gyro, it fixed collisions. Then I had to fix the issue of physics not slowing down the player anymore due to the platformstand property. Turns out, setting the
Velocity of the root part to
Vector3.new(0, 0, 0) whenever the player stopped moving their character solved the issue. The combination of all of these was the fix I was looking for. Thanks for the other answer (which had the right idea, but roblox reenabled what I disabled anyway) and the comments trying to help.
After running a few tests, the "Running"
HumanoidStateType, as well as a lot of others, seem to be keeping the
You could experiment more by using
:StateChanged and seeing what the
Humanoid is doing and disabling things from there:
Now you could also force set a
HumanoidStateType so the
Humanoid is forced to follow it. You do this by
RunService unless the
HumanoidStateType gets locked the first time you set it.
I have looked through some states and found the HumanoidStateType
Physics in which it's description is:
The Humanoid doesn’t apply any force on its own. (Unending PlatformStand) Has to be unset manually using
Isn't really a direct answer, but hopefully this can lead you to a solution to your problem. Good luck!