Model hover smoothly above player

Started working on new project. On this project, actual player model is being hidden out of camera bounds and replaced with other model that moving on Z coordinates.

  1. What i want to achieve?
    While player model is walking below the surface, model above is smoothly moving right\left, depending on HumanoidRootPart Z coordinate.

  2. What is the issue?
    A PlayerModel replacer is moving fine, but the moves are jittering, while i want it to be as smooth as possible (Look on vid. UPD: Whole vid looks jittery due to me using Roblox Recorder, which is quite crappy))

  3. What solutions i have tried?
    Tried to make it though Tweening, but i don’t have enough experience in tweening and math calculations. Have i tried Lerping? Lerping is just more complicated and worser version of Tween that used mostly for physic object, while i just need 1 model to hover Left and Right.

Here is a code i’m using right now (Removed useless parts from code to make it shorter):

local PModel = workspace.Interaction.PlayerModel

local Char = Player.Character
local RootPart = Char:FindFirstChild("HumanoidRootPart") or Char:WaitForChild("HumanoidRootPart")

local TS = game:GetService("TweenService")
local Tween = TweenInfo.new(0.1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

while true do
	local Goal = {CFrame = (CFrame.new(PModel.PrimaryPart.CFrame.X, PModel.PrimaryPart.CFrame.Y, RootPart.CFrame.Z))}
	
	local Tweeny = TS:Create(PModel.PrimaryPart,Tween,Goal)
	Tweeny:Play()
	wait()
end
4 Likes

Maybe if you used a constant velocity it would be better, in your code a tiny movement vs a giant one will take the same time, 0.1 seconds.

Here’s how you calculate time from velocity.

local time = distance / speed
3 Likes

At first weld constraints worked for me but when I make one part anchored stuff gets weird so Try @bytesleuth’s suggestion first

2 Likes

Is this run on a local script? Or just a normal script?

If its being run on a local script, I’d recomend using the RenderStepped signal apart of RunService. You could also use the open sourced Spring module to help with that. Otherwise (I know it may be annoying), just use lerp. Tweens shouldn’t be running that quickly.

If its being run on a server script, use body position and body gyro. You can set the max force vector on body gyro to math.huge so it does rotate, but you can tweak the max force on the body position to fit your “tweening” needs.

I’ve had this problem while creating a camera system. I looped tweens until it looked right, but it always jittered. The different ways above helps for whenever I am trying to match the player’s character with a part, a camera with a part, etc. LMK if you have any troubles! :slight_smile:

2 Likes

Script ran on server side. I probably will go with Body Velocity/Gyro, it sounds way more reliable.
Also about camera… Camera part is inside same Model with Jittering player model i’m trying to fix, however, Camera is moving EXTREMELY smoothly (Probably because Camera alligning itself with Camera part through LocalScript).

If jittering problem will continue, i will probably will use normal player model instead of simulating new one.

1 Like

Is there a reason why it is on server?

1 Like

Mostly, for protection. LocalScripts are easy to modify with any Injector. Server scripts are way more reliable for saving data and preventing some of the exploits.
This is the only reason i guess.

1 Like

Imo I don’t think you should worry about this. Making everything on server is extremely bad for performance, I say if no one except the client needs to see this part then you should do it on client.

1 Like

Came across this post when I was searching the forums on how to make a 2D Camera. Do you think this would be the right way of doing it? Because I feel like it worked out and all but I’m also getting a bit of a jitter from the camera, but that may just be due to me using RunService.

		local distance = math.sqrt((root.Position.X - cameraModel.Position.X)^2 + (root.Position.Y - cameraModel.Position.Y)^2)
		local speed = 50
		local timeFormula = distance / speed
		
		local cameraTween = game:GetService("TweenService"):Create(cameraModel, TweenInfo.new(timeFormula, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {
			CFrame = CFrame.new(root.Position) * CFrame.new(0, 10, cameraDistance)
		})
		
		cameraTween:Play()