How to properly modify character's position?

Hello, I want to keep character’s position always on the same Y-Axis, so it only moves on Z-Axis and X-Axis.

Currently I do:

while Character.Parent ~= nil do
    local RootCFame = Root.CFrame
    local Position = RootCFame.Position
    local Angles = RootCFame - Position
    local YPosition = 5

    Root.CFrame = CFrame.new(Vector3.new(Position.X, YPosition, Position.Z)) * Angles

    RunService.Heartbeat:Wait()
end

But the problem is that this causes my character to heavily jitter, while moving or standing still, sometimes it just gets flung if you walk in to a wall, etc.

My question is, how do I properly set root part’s CFrame to avoid any jittering while keeping the character always on the same axis?

(I’m doing all of this on client)

Hello there!
You could just do that:

while Character.Parent ~= nil do
    local RootCFame = Root.CFrame
    local Position = RootCFame.Position
    local Angles = RootCFame - Position
    local YPosition = 5

    Root.CFrame = CFrame.new(Vector3.new(Position.X, Position.Y, Position.Z)) * Angles

    RunService.Heartbeat:Wait()
end

(I’m really sorry but my english level isn’t high enough to explain what I modified, but I modified the 7th line.)

But this doesn’t do anything, please re-read the post, I need to set the specific Y position.

1 Like

Did you tried tweenservice? And if you ever tried it what was the result

TweenService interpolates a property from 1 point to another each frame. It will not be helpful in this case

1 Like

I don’t know what are you trying to achieve. But i can recommend you the “linear velocity”. If you get position to loop it will be jittered. But linear velocity won’t be jittered.

Well as you know, character is affected by the physics, tweening is ideal for anchored models. I want to keep the character on the same Y-Axis while all of the physics are applied to it, just a normal character, but the Y-Axis for position stays the same.

1 Like

I would do linear velocity and lock onto the Y-Axis and adjust to what I want, then change the HumanoidState to none or whatever to get the physics (not free fall or flying). I don’t know if this works but if it doesn’t, you must re-adjust the physics of the character(animation etc.) while linear velocity is lock onto the Y-Axis

Another way is to create a Part under the player and adjust the Y-Axis as you want, and make the Part follow player in the X-Axis and Z-Axis. You can keep the physics with this.

Sorry, if i can’t help you. This is max that i know.

Here is example script that i made:

local Runservice = game:GetService("RunService")
--Runservice

local Player = game:GetService("Players").LocalPlayer
Player.CharacterAdded:Wait()
local Character = Player.Character
local Root = Character:WaitForChild("HumanoidRootPart")
--Player,Character etc.

local Part = Instance.new("Part")
Part.Parent = game.Workspace
Part.Anchored = true
Part.Size = Vector3.new(19, 1, 22)
Part.Transparency = 1
--Part adjustments

Runservice.Heartbeat:Connect(function()
	if Root.Position.Y >= 8.498 then
		Part.Position = Vector3.new(Root.Position.X,5,Root.Position.Z)
		print(Root.Position)
	else
		print("Cannot")
	end
end)

You need to put in StarterPlayer. If you want this be in server i can make (actually thats what you need).

1 Like

Yeah this is close to what I want, however I need to do this with a humanoid root part, not with an additional part, i will let you know regarding the humanoid state

1 Like