Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make part move smoother?

Asked by 3 years ago
Edited 3 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

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
Try using RunService.RenderStepped since a while loop loops around ever 0.03 seconds which would not be effective for camera manipulation. uhi_o 417 — 3y

3 answers

Log in to vote
0
Answered by 3 years ago

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()
Ad
Log in to vote
0
Answered by 3 years ago

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.

Log in to vote
-1
Answered by
tomekcz 174
3 years ago

try learning about tweens

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. ProjectInfiniti 192 — 3y

Answer this question