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

CFrame and Interpolation for player body parts?

Asked by
ZarceI 0
8 years ago

I want to make a smooth walk animation using Interpolation but I don't know where to start writing my code. I've been wanting to learn interpolation for years and hopefully I went to the right site this time. Thank you very much.

0
Use animation editor for player based animations. For anything else try out lerp and modules. Abstract_Life 65 — 8y
0
@Abstract_Life I want someone to teach me HOW to use lerp..... ZarceI 0 — 8y
0
Search the wiki, it has a lot of helpful documentation there. TheHospitalDev 1134 — 8y
0
The wiki didn't help me that's why I came here.. ZarceI 0 — 8y
View all comments (2 more)
1
If the wiki doesn't help you, then you should learn how to script first. Destrings 406 — 8y
0
I thought this site is suppose to help people that need HELP on a certain bit that they aren't understanding. Not by telling them to go to the wiki when I clearly said it didn't HELP me. ZarceI 0 — 8y

1 answer

Log in to vote
0
Answered by
OniiCh_n 410 Moderation Voter
8 years ago
Edited 8 years ago

Interpolation isn't all that helpful for player animations unless you're using custom players/rigs. If you're still using the default ROBLOX character rigs, either R6 or R15, it's much easier to use the Animation Editor and replacing the default Walk animation with your new one.

wiki article on using the Animation object in ROBLOX

Linear interpolation, or "lerp", is great for moving non-player objects. The built in CFrame:Lerp() method is applied to the origin CFrame (or Vector3), takes the end position and interval as arguments, and returns the point between the beginning and end positions at the given interval.

The interval should be a fraction, with 0 representing the beginning point and 1 representing the end position.

Using this method combined with a simple loop, we can smoothly transition parts along these points.

Example code:

local part = script.Parent
local EndPosition = CFrame.new(x, y, z) --Establish where we want the part to end.

for _, i = 0, 1, 0.1 do
--The 3rd number represents the rate at which the interval (i) is updated

    part.CFrame = part.CFrame:lerp(EndPosition, i)
--CFrame:lerp() is called on the part's current position, and takes the EndPosition as its destination and i as its interval, with i increasing by 0.1 every 0.01 seconds.

    wait(.01)
--The smaller the wait(), the "smoother" the lerp will look, but it will be much faster.

end

This simple loop above moves the part from its current position to the EndPosition in about 0.1 seconds. We get this estimated time by dividing 1 by the interval amount, then multiplying it by the wait() time. (Or 1 / 0.1 x 0.01 in this case)

Hope this helps you understand how :Lerp() works. This also applies to Vector3 values as well, as both CFrame:lerp() and Vector3:Lerp() take the same arguments.

Ad

Answer this question