Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Anyone got advice for smooth(not jittery) player.Y restriction?(Will explain below)

Asked by 3 years ago
Edited 3 years ago

I'm setting up a swimming system where you can't Swim past the OceanLevel(being the Y height of the water maximum) As it is, its really jittery and I've tried ways in making it smooth(no jittery motions) but its always crashed the script(not the game)

OceanLevel.Value = -12.1 Angle is the Y angle of the players camera movement.(whichever movement) == 1(means true) Feel like its the way "Player.Character:MoveTo" works that makes it jittery but that's a personal assumption

if (script.IsSwimming.Value == true and Human.Position.Y > OceanLevel.Value and angle >= 0) or 
       (script.IsSwimming.Value == true and Human.Position.Y > OceanLevel.Value and angle <= 0 and movement.backward == 1) or 
       (script.IsSwimming.Value == true and Human.Position.Y > OceanLevel.Value and angle <= 0 and movement.upward == 1) or
       (script.IsSwimming.Value == true and Human.Position.Y > OceanLevel.Value and angle <= 0 and movement.upward == 1 and movement.forward == 1)
        then
        Player.Character:MoveTo(Vector3.new(Human.Position.X, OceanLevel.Value, Human.Position.Z))
    end

Any advice/tips on fixing this would be a great help!

1
try using something like Heartbeat so it wont look jittery on the client, it doesnt matter much if its jittery on the server cause no one will be seeing it. Benbebop 1049 — 3y
1
Does Heartbeat run faster then while wait() do? or is it something different? DylanD319 9 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Not sure if this is the answer you’re looking for but if moving a few pixels is alright you can always set a BodyPosition that can only move on the y axis. Using heartbeat like that comment said would work too since I believe it runs every time the game renders.

0
I did end up finding the answer right after I read Benbebop's comment. I was using BodyVelocity and BodyGyro and realized instead of setting the Player position I can make the BodyVelocity Y = 0 for the duration that its over OceanLevel. DylanD319 9 — 3y
1
I'd like to say thankyou tho for actually giving an answer, I have a tendency to ask a question or for assistance and figure it out right after. So yes thankyou for giving a possible solution! DylanD319 9 — 3y
Ad

Answer this question