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

How would i make this go smoother than it initially is?

Asked by 4 years ago

Smoothening.

I'm completely aware of tweening and lerping but i don't really know how to do it in this situation.

The script is working 100% well, but i just want it to be smoother;

SCRIPT

local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:wait() ; Character = Player.Character
    local Torso = Character:WaitForChild'Torso'
    local Neck = Torso:WaitForChild("Neck")

    local Humanoid = Character:WaitForChild("Humanoid")
    Humanoid.AutoRotate = false
    local HMR = Character:WaitForChild("HumanoidRootPart")

    local Mouse = Player:GetMouse()

    local RC0 = CFrame.new(1, .5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
    local RC1 = CFrame.new(-.5, .5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)

    local LC0 = CFrame.new(-1, .5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
    local LC1 = CFrame.new(.5, .5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)

    local NeckC0 = Neck.C0
    local NeckC1 = Neck.C1

    while wait(1) do
        local cf = workspace.CurrentCamera.CFrame.lookVector.Y

        Neck.C0 = NeckC0 * CFrame.Angles(math.asin(Mouse.Origin.lookVector.Y), 0, 0):inverse()
        HMR.CFrame = CFrame.new(HMR.Position, Vector3.new(Mouse.Hit.p.x, HMR.Position.Y,Mouse.Hit.p.z))
    end
0
If you reduce the wait() time (and the amount you are changing it by each time) it should look smother. Note that wait() isn't guaranteed to be exact. Learning TweenService would be extremely beneficial here. centraltrains 60 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

If this is a ServerScript, you can use RunService's Stepped event, that fires every frame prior to the physics simulation.

while game:GetService("RunService").Stepped:wait() do
    --// Rest of code
end

OR - The code is the same, just formatted differently.

local RS = game:GetService("RunService")

while RS.Stepped:wait() do
    --// Rest of code
end

If this is a LocalScript, you can use the same thing, except using RenderStepped instead of Stepped. This fires every frame prior to the frame being rendered.

while game:GetService("RunService").RenderStepped:wait() do
    --// Rest of code
end

OR - The code is the same, just formatted differently.

local RS = game:GetService("RunService")

while RS.RenderStepped:wait() do
    --// Rest of code
end

Either way, these will be fired every frame.

  • RenderStepped can only be called in a LocalScript.

  • Stepped can only be called in a ServerScript.

(You could use RunService.Heartbeat:wait(), which can only be used in a LocalScript, but I'd use RenderStepped over Heartbeat)


Hope this helped! Feel free to select this as an answer if this worked for you!


Documentation + API

Ad

Answer this question