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

I have an issue with using CFrame:lerp And my attempts are not working?

So for my first person shooter I made it so that the fake arms are suppose to move to a specific point when doing a motion which I set but its not working

Here are the variables I set

local moveOffset 		= CFrame.new(0.02, -0.014, -0.009)
local lerpTime 			= .2

The code below is all done in renderstepped (I already did a print to check if moving is true and fakeArms are in the camera which do work as I already set their humanoidrootpart to the camera cframe but its torso is not moving.)

local startCFrame = fakeArms.Torso.CFrame
if moving then
	fakeArms.Torso.CFrame:lerp(startCFrame * moveOffset, lerpTime)
else
	fakeArms.Torso.CFrame:lerp(startCFrame, lerpTime)
end

That did not work so I thought I'd need to keep adding the lerp time so I did it like this next.

local lerpTime 			= 0

Again the code below is all done in renderstepped

local startCFrame = fakeArms.Torso.CFrame
if moving then
	if lerpTime < 1 then
		lerpTime = lerpTime + .2
	end
	fakeArms.Torso.CFrame:lerp(startCFrame * moveOffset, lerpTime)
else
	fakeArms.Torso.CFrame:lerp(startCFrame, lerpTime)
end

If anyone knows the issue thanks for helping me in advance! :) ~KIHeros

3 comments

0

you are doing it wrong...

0

May you tell me what I am doing wrong? I am new to lerp sorry :/

0

@UniversalDreams, you did not need to downvote him. His question is better structured than some of the content I've seen on the site. If you're downvoting him for the fact that he is "using lerp wrong", that is why he is asking the question. How would you feel if you asked a question and I upright downvoted you for getting the script wrong? Think before targeting a user.

1 answer

✓ Accepted answer

There's a few complications here but I'll point out one I saw. This whole thing should make it move, but by the looks of things not how you want.


If you're not moving:

The CFrame will be set to a fraction of the fakeArms.Torso's CFrame and startCFrame, once. Which is presumably not what you expected. If you wanted it to reset to startCFrame then you should have just set it. If you wanted it to tween back, you'd have to adjust lerpTime

If you're moving:

Those iterations aren't doing quite what you expect. It's not a lerp in the most normal sense, at the very least - The first iteration (0.2) is 0.2 of the way there. The second iteration is not 0.4 of the way there, and is fact 0.2+0.8*0.4 of the way there (uh-oh). The third follows this nasty recursive convention, as does the fourth, and the fifth is finally startCFrame*moveOffset

3 comments

0

Well I'm not sure what I did to deserve that downvote so swiftly...

0

I did not downvote it.

0

Probably Universal being unhappy that somebody would try to help on ScriptingHelpers.

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