Hello,
In my script I’m lerping from one cframe to another. But the outcome when I lerp with an alpha of 1 is not what it should be.
Module script for lerping:
-- @ Interpolation
-- // Variables
-- # Tables
local sequence = {}
-- // Functions
sequence.__index = sequence
function sequence.new(target: Instance, property: string, keyframes: {})
local data = {}
setmetatable(data, sequence)
data.Target = target
data.Property = property
data.Keyframes = keyframes
return data
end
function sequence:start()
for _, keyframe in pairs(self.Keyframes) do
local target = self.Target
local property = self.Property
local origin = target[property]
local length = keyframe["Length"]
local change = keyframe["Change"]
local interpolation = 0
repeat task.wait(length / 10)
interpolation += 1
target[property] = origin:Lerp(change, interpolation / 10)
until math.floor(interpolation / 10) >= 1
task.wait(2.5)
end
end
return sequence
Script where I run the module (I put comments after the cframes to help identify them):
-- @ Accessory
-- // Variables
-- # Services
local replicatedStorage = game:GetService("ReplicatedStorage")
local playersService = game:GetService("Players")
-- # Modules
local model = require(script:WaitForChild("Model"))
local sequence = require(script:WaitForChild("Sequence"))
-- # Folders
local assets = replicatedStorage:WaitForChild("Assets")
local swordAssets = assets:WaitForChild("Sword")
local swordAnimations = swordAssets:WaitForChild("Animations")
-- # Models
local swordSet = swordAssets:WaitForChild("Set")
-- // Functions
playersService.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local animationController = humanoid:WaitForChild("Animator")
local set = model.unpack(swordSet:Clone(), character)
local grip = set["Handle"]:WaitForChild("Grip")
grip.Part1 = humanoidRootPart
task.wait(5)
sequence.new(set["Hilt"]:WaitForChild("Joint"), "C0", {
{ ["Length"] = 1, ["Change"] = CFrame.new(-7.4, 0, 0) },
{ ["Length"] = 1, ["Change"] = CFrame.new(1.25, -1.25, 1) * CFrame.Angles(0, 0, math.rad(120)) }
}):start()
animationController:LoadAnimation(swordAnimations:WaitForChild("Wield")):Play()
task.wait(5)
sequence.new(set["Hilt"]:WaitForChild("Joint"), "C0", {
{ ["Length"] = 1, ["Change"] = CFrame.new(1.75, -1.25, 0.5) * CFrame.Angles(0, math.rad(35), math.rad(120)) }, -- From where I'm lerping
{ ["Length"] = 1, ["Change"] = CFrame.new(1.5, 0.9, 1.2) * CFrame.Angles(math.rad(-45), math.rad(-35), math.rad(-160)) } -- To where I'm lerping to
}):start()
end)
end)
After I run the script ingame the joints “C0” is:
Position: 1.5, 0.9, 1.2
Orientation: -35.393, -44.721, -130.161
But how can that be? I appreciate any help!