You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Attempting to lerp a sprint animation.
What is the issue? Include screenshots / videos if possible!
Without lerping and just using CFrame:PivotTo
With lerping
No matter what I set the value to it goes into the same spot shown in this video.
elseif input.KeyCode == Enum.KeyCode.LeftShift then
if humanoid then
if humanoid.Health > 0 then
humanoid.WalkSpeed = 20
sprinting = true
local targetCFrame = viewmodel.PrimaryPart.CFrame * CFrame.new(-.4, -4.7, -0.35)
for i = 0, 1, 0.01 do
task.wait()
viewmodel.PrimaryPart.CFrame:Lerp(targetCFrame, i)
end
I however do have this running through a heartbeat function too…
viewmodel:WaitForChild("RootPart"):PivotTo(
-- sway
hrp.CFrame * CFrame.new(movementsway.Position.X / 2, movementsway.Position.Y / 2, 0)
* CFrame.Angles(0, -mousesway.Position.X, mousesway.Position.Y)
* CFrame.Angles(0,movementsway.Position.Y * sprintswaymultiplier, movementsway.Position.X * sprintswaymultiplier)
-- recoil
* CFrame.Angles(gunspring.Position.X, gunspring.Position.Y, 0)
* CFrame.new(0, 0, gunspring.Position.X * 5)
-- + Vector3.new(-.4, -4.7, -0.35) -- this is how the movement was handled prior to lerping
)
that controls the recoil + cam and weapon sway when walking. As you can see the first video adds the value as a vector3, and the second video multiplies it as a CFrame. (I think this might have something to do with it?)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Can’t find a solution
Does adding a Vector3 to a CFrame work? I never even tried doing that.
Your first section of code that has the Lerp is likely just being overwritten. The heartbeat version works, because that is where you should be updating the CFrame (within Heartbeat) Task Scheduler | Documentation - Roblox Creator Hub
Well, if I I’m understanding correctly. I guess adding a vector3 is just giving an offset to the position of the CFrame? I assume CFrame * CFrame.new(Vector3) is the equivalent to CFrame + Vector3?
Lol now I’m feeling stupid. I’ve always just multiplied a default oriented CFrame.
So perhaps in the hearbeat method, do the pivot calculations and then perform the lerp to the resulting Cframe
Well now I just need to understand the goal. The V3 being added was just giving the CFrame of the viewModel root part an offset. Your changing that to lerping toward a targetCFrame. I’m not sure those things are accomplishing the same goal.
When lerping in an active context, something that is being updated every frame, you are not going to want to use the approach where you have a separate thread iterating through a full alpha over the course of roughly 100 frames, as done here
local targetCFrame = viewmodel.PrimaryPart.CFrame * CFrame.new(-.4, -4.7, -0.35)
for i = 0, 1, 0.01 do
task.wait()
viewmodel.PrimaryPart.CFrame:Lerp(targetCFrame, i)
end
What you’re essentially doing there is a fixed tween, which won’t work well with all of the conflicting operations being done on the same objects and values regularly. Instead you’re going to want to only update a targetCFrame, and then use the heartbeat to lerp inbetween the current and target cframe
EDIT:
But rather than reinventing the wheel, you may want to look into blending roblox animations using adjustWeight on animation tracks
That’s true actually, I might just do that. I just completely wrote off the option of personally making any animations but this would be very simple to do. Thank you guys, I don’t know why I didn’t think to do that…