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

Is there anyway to make animations easier?

Asked by 8 years ago

So I was wondering if there is any way to make animating body parts easier like not the plugin but, I am talking about the angle so that CFrame.Angles how would I get the perfect coordinates for that to do things? I hope someone can help me out with this I want to know how to get the correct coordinates a bit easier so that if I need the arms to be in an animation until the player stops pressing that certain button or loop an animation so basically he arms stay in one position until the player unequips the tool.

1 answer

Log in to vote
1
Answered by 8 years ago

Lerp is quite a fun way of interpolating (smoothly transitioning) between vectors/CFrames.

This article is quite good at explaining it. If you are having trouble with it then drop a comment and I'll try and re-explain it.

As requested to expand:

So, lerp is essentially a mathematical function which you can use to work out a point between two CFrame/vector3s

It is used like the following:

FIRST_CFRAME:lerp(FINAL_CFRAME, FRACTION)

FIRST_CFRAME:

This is the starting position/cframe

FINAL_CFRAME:

This is the ending point, which you want the part to end up at.

(This can be a Vector3 as well, works the same way)

FRACTION:

This fraction will represent how far along the path (between the part's position and end FINAL_CFRAME) the function will get a value from.

So if you imagine the following scenario:

FirstPosition = Vector3.new(0, 0, 0)
FinalPosition = Vector3.new(4, 0, 0)

FirstPosition:lerp(FinalPosition, 0.5) will return Vector3.new(2, 0, 0) as it is half way (0.5 out of 1) between the FirstPosition and the Final position.

To put this into a script, you can tween between points using:

local FirstCFrame = workspace.Part.CFrame --Get the original CFrame
local FinalCFrame = CFrame.new(0, 50, 0) --Get the final CFrame

for i=1,50 do --Lets go with 50 frames
    local NewCFrame = FirstCFrame:lerp(FinalCFrame, i/50) --Use lerp to get the CFrame
    workspace.Part.CFrame = NewCFrame --Set the part's CFrame to the lerp'd CFrame
    wait(0.25) --So it isn't instantaneous
end

I hope this helped! Please comment below if you have more questions.

0
I don't understand how u would use Lerp with Roblox like.... game.Workspace.Part.Position:Lerp(Vector3.new(10,0,0))? Is that how you would use Lerp? KingLoneCat 2642 — 8y
0
@KingLoneCat Edited, also you'll need to use welds for your animation example darkelementallord 686 — 8y
0
Add a wait() in the loop or else you won't see the actual interpolation. XAXA 1569 — 8y
0
@XAXA Thanks, can't believe I missed that, lol darkelementallord 686 — 8y
View all comments (2 more)
0
Let's say I wanted to do animations with the Character and I wanted to move the body part to a specific place with CFrame.Angles so in other words lerp it there... Is there any way to get exact coordinates of that spot that I am Lerping to? Such as if I want the arm to move to the back of the torso is there anway to lerp it there because everytime I use CFrame.Angles the arm teleports to the cente KingLoneCat 2642 — 8y
0
@KingLoneCat You multiply the CFrame position by the CFrame.Angles. darkelementallord 686 — 8y
Ad

Answer this question