Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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!

2 comments

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.

1

Does Heartbeat run faster then while wait() do? or is it something different?

1 answer

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.

2 comments

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.

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.