Answered by
6 years ago Edited 6 years ago
An efficient and amazing method for smoothly interpolating properties is the TweenService.
TweenService supports interpolation for several different data types, including CFrame. You can access the service using:
1 | game:GetService( "TweenService" ); |
Below I have outlined how you would use the TweenService to create the desired effect:
01 | local TweenService = game:GetService( "TweenService" ); |
03 | local TweenDetails = TweenInfo.new( |
05 | Enum.EasingStyle.Quint, |
06 | Enum.EasingDirection.Out, |
12 | local TweenProperties = { |
13 | [ "CFrame" ] = CFrame.new(rootPart.Position, (mouse.Hit.p*Vector 3. new( 1 , 0 , 1 )) + (rootPart.Position*Vector 3. new( 0 , 1 , 0 ))) |
16 | local Tween = TweenService:Create(rootPart, TweenDetails, TweenProperties); |
Because the HumanoidRootPart is welded to all the other parts in a character, you can simply tween it instead of having to tween each individual part or trying to use the :SetPrimaryPartCFrame() method. You would want to put lines 12-17 inside of the function your event is calling. Let me know if you need additional help on how to implement this.
The TweenService is a super valuable service that can save you loads of time.
Extra Reading:
Types of EasingStyles