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

How to make part move smoother?

I am making a camera that follows your character and I used BodyPosition to follow my character, but it doesn't look very smooth and I'm wondering if anyone can help me make it more smoother.

https://gyazo.com/33b1859e12525ca9e5c940b57c29a0fb

This is what I got so far

local torso = script.Parent.HumanoidRootPart

local center = Instance.new("Part")
    center.CanCollide = false
    center.Size = Vector3.new(1,1,1)
    center.Parent = game.Workspace
	center.Transparency = 1
local bp = Instance.new("BodyPosition")
    bp.maxForce = Vector3.new(9e+100, 9e+100, 9e+100)
    bp.P = 40000
    bp.Parent = center

local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer

repeat wait() until player.Character
camera.CameraType = "Scriptable"

local bp2 = Instance.new("BodyPosition")
	bp2.MaxForce = Vector3.new(9e+100, 9e+100, 9e+100)
	bp2.P = 40000
	bp2.Parent = camera

while torso.Parent do
	center.BodyPosition.position = torso.Position + Vector3.new(0,7,26)
	camera.CFrame = center.CFrame
	wait()
end

center:Destroy()

1 comment

1

Try using RunService.RenderStepped since a while loop loops around ever 0.03 seconds which would not be effective for camera manipulation.

3 answers

Use Renderstepped to update the camera

local torso = script.Parent.HumanoidRootPart
 
local center = Instance.new("Part")
center.CanCollide = false
center.Size = Vector3.new(1,1,1)
center.Parent = game.Workspace
center.Transparency = 1
local bp = Instance.new("BodyPosition")
bp.maxForce = Vector3.new(9e+100, 9e+100, 9e+100)
bp.P = 40000
bp.Parent = center
	 
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
	 
repeat wait() until player.Character
camera.CameraType = "Scriptable"

local bp2 = Instance.new("BodyPosition")
bp2.MaxForce = Vector3.new(9e+100, 9e+100, 9e+100)
bp2.P = 40000
bp2.Parent = camera

game:GetService("RunService").RenderStepped:Connect(function(dt)
	center.BodyPosition.position = torso.Position + Vector3.new(0,7,26)
	camera.CFrame = center.CFrame
end)

center:Destroy()

I do not know if this would work with your code, but this has always worked for me.

Try using a simple Lerp()

local movingPart = game.Workspace.Part
local end = game.Workspace.Part2

-- this loop moves the part by a percentage.  It will move 100% towards the ending part until it reaches the exact position.
for i = 0, 1, .1 do
	wait()
	movingPart.CFrame = movingPart.CFrame:Lerp(end.CFrame, i)
end

You might also try tweenservice, which smoothly moves the part and you can even select a style you want it to move.

local tweenservice = game:GetService("TweenService")
local part = game.Workspace.Part  -- this is the part you want to move
local end = game.Workspace.Part2 -- this is the part you want to move to

local tweeninfo = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0) -- this modifies each aspect of how the part moves.  The total move time takes 3 seconds, moves in a linear fashion, does not repeat or reverse, and has no delay)

local partTween = tweenservice:Create(part, tweeninfo, end.Position):Play()

again, these may not work for your code, nor will they fit the context. But using these may give some ideas.

try learning about tweens

1 comment

0

tweens are a bit more complicated because you would need to calculate the amount of time an individual tween needs, or else if you move like 0.1 studs, the camera will VERY slowly follow the player.

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