Still have questions? Join our Discord server and get real time help.
4

# How can I use the necessary features of PlatformStand while avoiding the negative downsides?

Asked by 5 days ago

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 HumanoidRootPart's CFrame.

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


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.

Thanks!

0
If you see a variable that isn't defined in the script, or looks like I'm not defining it locally, don't worry. All variables are declared properly at the beginning of the LocalScript. AetherProgrammer 50 — 5d
0
Best option here would be to use a BodyGyro instead of changing the CFrame directly. From my experiences this shouldn't interfere with PlatformStand. ThatPreston 277 — 5d