Smooth moving object in air

What is the best way to move an object in air? I tried tween service but in the server script is unsmooth and in local script it is weird.
In local script:

2 Likes

Can you provide us with more information like your code?
Because right now we have no clue what’s jittering the movement
The tween service is smooth unless if you experience lag or using it the wrong way.

For what it seems like you want, use Lerp, here is a helpful video on it.

Could you show us your localscript code?

By the way it is welded object
Here is the script:

local lanovka = game.Workspace.LanovkaNHR.Part2
local RunService = game:GetService("RunService")
local Starter = game.Workspace.Lan.Starter

local tweeningInformation = TweenInfo.new(
    30,   
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)
local startLan = {CFrame = CFrame.new(131.08, 67.88, 83.44)
}
local startLanS = TweenService:Create(lanovka,tweeningInformation,startLan)

Starter.Touched:Connect(function(hit)
	
    startLanS:Play()
end)

I tried lerping but I need to move object more times at one speed, the part would have to stop and then go to another place every time.

Code in local script and script is the same. Should be code in the local script different?

Put your code in a code block by typing this three times `.

1 Like

I think this has to do with the replication rate. Let’s say you’re tweening the position of a part, tweening it one stud higher. How tweening works is it changes the position by a little amount slowly to make it smooth, like (0, .1, 0), then to (0, .2, 0), and so fourth. There’s nothing wrong with your code. If you want to achieve a smoother effect, have the server fire a remote event to all clients and have the clients tween the part, to avoid the replication rate.

I think what you need to do is add a debounce to your touched event. Try making it so the touched event fires and plays the tween, but make it so the tween can’t play if it is already playing.

When it is in the local script it looks smoother but it still shaking when I´m sitting on it.

It didn’t help, it is still shaking.

You should make a loop for a counter, meaning that it will repeat every milliseconds and it will look smooth, there isn’t really actually smooth but illusions of it being smooth by the frames they move. A loop will fix this problem by moving it without a stop until it needs to.

If you mean something like this:

	local part = script.Parent
	for i = 1, 200 do
		part.CFrame = part.CFrame * CFrame.new(0.1 ,0,0)
		wait(0.001)
	end
end

It looks better but it is a little laggy but it is better. The main problem is when I want to move it faster, it is very unsmooth.

1 Like

You could try using this:


wait(2.5 + math.random())
local hZ = 1 / 60
local speed = .1
local start = CFrame.new(0, 0, 0) -- Set this to be equal to what the start position of the part should be.
local End = CFrame.new(0, 5, 100) -- Where you want to move the part to.

function movemodel(model,start,End,AddBy)
    local i = 0
	repeat
		local x = game:GetService("RunService").Heartbeat:Wait() / hZ
		i = math.clamp(i + (AddBy * x), 0, 1)
		if not model.PrimaryPart then break end
        model:SetPrimaryPartCFrame(start:Lerp(End,i))
	until model.PrimaryPart.CFrame == End
end

local dist = (Start.p - End.p).Magnitude / speed

local add = 1 / dist

movemodel(workspace.TestModel, start, End, add)
3 Likes

Wau, this is what I need. Thank youu!!

2 Likes