AnimationTrack

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음

에서 애니메이션의 재생을 제어합니다. 이 개체는 생성할 수 없으며, 메서드에 의해 반환됩니다.

요약

속성

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    Animation 를 생성하는 데 사용된 개체입니다.The object that was used to create this AnimationTrack .

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    AnimationTrack가 재생될 때 true를 반환하는 읽기 전용 속성.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    AnimationTrack의 길이(초)를 반환하는 읽기 전용 속성입니다.애니메이션이 완전히 로드될 때까지 0이 반환되어 즉시 사용할 수 없을 수 있습니다.

  • 병렬 읽기

    애니메이션이 완료된 후 반복할지 여부를 설정합니다. 결과를 재생하는 동안 변경되면 애니메이션이 완료된 후에 효과가 적용됩니다.

  • AnimationTrack의 우선 순위를 설정합니다.이것이 무엇인지에 따라 한 번에 여러 애니메이션을 재생하면 이 속성을 확인하여 어느 Class.Keyframe``Class.Pose|Poses 가 서로 재생되어야 하는지 알아볼 수 있습니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    AnimationTrack의 속도는 AnimationTrack의 현재 재생 속도를 제공하는 읽기 전용 속성입니다.기본값은 1입니다.속도가 1과 같을 때 애니메이션이 완료하는 데 걸리는 시간은 AnimationTrack.Length (초)와 같습니다.

  • 복제되지 않음
    병렬 읽기

    AnimationTrack가 소스 애니메이션을 재생하는 동안 시간 내에 위치를 반환합니다.트랙을 애니메이션의 특정 순간으로 점프하도록 설정할 수 있습니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    현재 무게를 제공하는 읽기 전용 속성입니다 AnimationTrack. 기본값은 1입니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    현재 무게를 제공하는 읽기 전용 속성 AnimationTrack입니다.

메서드

이벤트

  • 이전 애니메이션 루프가 끝난 후 다음 업데이트에서 AnimationTrack 루프가 발생하면 화재합니다.

  • 세계에서 아무것도 이동하는 것이 완전히 끝났을 때 AnimationTrack가 발생합니다.애니메이션이 재생을 마쳤고, "페이드 아웃"이 완료되었으며, 주제가 중립 자세에 있습니다.

  • 플레이백의 AnimationTrack 재생 시마다 기본 이름 - "키프레임"이 없는 Keyframe에 도달합니다.

  • AnimationTrack가 재생을 마칠 때 화재가 발생합니다.애니메이션 트랙은 애니메이션이 "사라지는" 동안 주제를 여전히 애니메이션할 수 있습니다.애니메이션 트랙이 세계에서 아무것도 이동하는 것을 완료했을 때 캡처하려면 AnimationTrack.Ended 이벤트를 사용하십시오.

속성

Animation

읽기 전용
복제되지 않음
병렬 읽기

Animation 를 생성하는 데 사용된 개체입니다.The object that was used to create this AnimationTrack .To create an AnimationTrack , you must load an Animation object onto an Animator using the Animator:LoadAnimation() method.

코드 샘플

The following code sample prints the name of an animation whenever an AnimationTrack plays on a Humanoid. This script can be placed in a model with a Humanoid child.

Listen For New Animations

local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
animator.AnimationPlayed:Connect(function(animationTrack)
local animationName = animationTrack.Animation.Name
print("Animation playing " .. animationName)
end)

IsPlaying

읽기 전용
복제되지 않음
병렬 읽기

AnimationTrack가 재생될 때 true를 반환하는 읽기 전용 속성.

이 속성은 개발자가 애니메이션을 재생하기 전에 애니메이션이 이미 재생되고 있는지 확인하기 위해 사용할 수 있습니다(그렇지 않으면 재시작됩니다).개발자가 모든 재생 AnimationTracks 을 얻으려고 하면 Animator 또는 Humanoid 에서 사용해야 합니다. Animator:GetPlayingAnimationTracks()

코드 샘플

This code sample includes a simple function that will play an AnimationTrack if it is not playing, or otherwise adjust its speed and weight to match the new parameters given.

AnimationTrack IsPlaying

local function playOrAdjust(animationTrack, fadeTime, weight, speed)
if not animationTrack.IsPlaying then
animationTrack:Play(fadeTime, weight, speed)
else
animationTrack:AdjustSpeed(speed)
animationTrack:AdjustWeight(weight, fadeTime)
end
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playOrAdjust(animationTrack, 1, 0.6, 1)

Length

읽기 전용
복제되지 않음
병렬 읽기

AnimationTrack의 길이(초)를 반환하는 읽기 전용 속성입니다.애니메이션이 완전히 로드될 때까지 0이 반환되어 즉시 사용할 수 없을 수 있습니다.

AnimationTrack.SpeedAnimationTrack 가 1과 같으면 애니메이션이 완료하는 데 걸리는 시간은 AnimationTrack.Length (초)입니다.

코드 샘플

The following function will play an AnimationTrack for a specific duration. This is done by changing the speed of the animation to the length of the animation divided by the desired playback duration. This could be used in situations where a developer wants to play a standard animation for different duration (for example, recharging different abilities).

Playing Animation for a Specific Duration

local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)

Looped

병렬 읽기

이 속성은 애니메이션이 완료된 후 반복할지 여부를 설정합니다.플레이하는 동안 변경되면 애니메이션이 완료된 후에 결과가 적용됩니다.

반복 속성은 AnimationTrack 애니메이션 편집기에서 설정된 대로 기본값으로 설정됩니다.그러나 이 속성을 변경하여 게임이 실행되는 동안 AnimationTrack에 대한 제어를 할 수 있습니다.루프는 역방향으로 재생되는 애니메이션(음수 AnimationTrack.Speed )도 올바르게 처리합니다.첫 번째 키프레임에 도달한 후, 마지막 키프레임에서 다시 시작됩니다.

이 속성을 사용하면 개발자가 Roblox에 두 가지 버전을 업로드할 필요 없이 동일한 애니메이션의 루프 및 비루프 변형을 가질 수 있습니다.

코드 샘플

The animation in this example normally loops. After the player and the animation are loaded the animation is played in a non-looped fashion then in a looped fashion.

Animation Looping

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507770453"
local animationTrack = animator:LoadAnimation(animation)
animationTrack.Looped = false
task.wait(3)
animationTrack:Play()
task.wait(4)
animationTrack.Looped = true
animationTrack:Play()

The function in this code sample will play an AnimationTrack on a loop, for a specific number of loops, before stopping the animation.

In some cases the developer may want to stop a looped animation after a certain number of loops have completed, rather than after a certain amount of time. This is where the DidLoop event can be used.

Play AnimationTrack for a Number of Loops

local function playForNumberLoops(animationTrack, number)
animationTrack.Looped = true
animationTrack:Play()
local numberOfLoops = 0
local connection = nil
connection = animationTrack.DidLoop:Connect(function()
numberOfLoops = numberOfLoops + 1
print("loop: ", numberOfLoops)
if numberOfLoops >= number then
animationTrack:Stop()
connection:Disconnect() -- it's important to disconnect connections when they are no longer needed
end
end)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playForNumberLoops(animationTrack, 5)
병렬 읽기

이 속성은 AnimationTrack의 우선 순위를 설정합니다.이것이 무엇인지에 따라 한 번에 여러 애니메이션을 재생하면 이 속성을 확인하여 어느 Class.Keyframe``Class.Pose|Poses 가 서로 재생되어야 하는지 알아볼 수 있습니다.

우선 순위 속성은 AnimationTrack Studio의 애니메이션 편집기에서 설정되고 게시된 방식으로 기본값을 설정합니다.우선 순위 7 수준을 가진 Enum.AnimationPriority을 사용합니다.

  1. 액션4(최우선 순위)
  2. 액션3
  3. 행동 2
  4. 액션
  5. 이동
  6. 유휴
  7. 코어(최우선 순위)

편집기를 통해 또는 이 속성을 통해 올바르게 애니메이션 우선 순위를 설정하면 여러 애니메이션을 충돌하지 않고 재생할 수 있습니다.두 개의 플레이 애니메이션이 대상에게 다른 방식으로 동일한 신체 부위를 이동하도록 지시하는 경우, 가장 높은 우선 순위를 가진 AnimationTrack가 보다.두 애니메이션이 동일한 우선 순위를 가지는 경우 트랙의 무게가 애니메이션을 결합하는 데 사용됩니다.

이 속성은 개발자가 Roblox에 추가 버전을 업로드할 필요 없이 다른 우선순위에서 동일한 애니메이션을 재생할 수도 있습니다.

Speed

읽기 전용
복제되지 않음
병렬 읽기

AnimationTrack의 속도는 AnimationTrack의 현재 재생 속도를 제공하는 읽기 전용 속성입니다.기본값은 1입니다.속도가 1과 같을 때 애니메이션이 완료하는 데 걸리는 시간은 AnimationTrack.Length (초)와 같습니다.

속도가 조정되면 트랙이 재생하는 실제 시간은 길이를 속도로 나누어 계산할 수 있습니다.속도는 단위가 없는 양입니다.

속도를 사용하여 동일한 애니메이션의 길이를 다른 게임 이벤트(예: 능력 재충전)에 연결할 수 있으면서도 동일한 애니메이션의 다른 변형을 업로드할 필요가 없습니다.

이 속성은 읽기 전용이며, AnimationTrack:AdjustSpeed()를 사용하여 변경할 수 있습니다.

코드 샘플

In this example a player and an animation is loaded. The Length of an AnimationTrack determines how long the track would take to play if the speed is at 1. If the speed is adjusted, then the actual time it will take a track to play can be computed by dividing the length by the speed.

Animation Speed

local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507770453"
ContentProvider:PreloadAsync({ animation })
local animationTrack = animator:LoadAnimation(animation)
local normalSpeedTime = animationTrack.Length / animationTrack.Speed
animationTrack:AdjustSpeed(3)
local fastSpeedTime = animationTrack.Length / animationTrack.Speed
print("At normal speed the animation will play for", normalSpeedTime, "seconds")
print("At 3x speed the animation will play for", fastSpeedTime, "seconds")

The following function will play an AnimationTrack for a specific duration. This is done by changing the speed of the animation to the length of the animation divided by the desired playback duration. This could be used in situations where a developer wants to play a standard animation for different duration (for example, recharging different abilities).

Playing Animation for a Specific Duration

local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)

TimePosition

복제되지 않음
병렬 읽기

AnimationTrack가 소스 애니메이션을 재생하는 동안 시간 내에 위치를 반환합니다.트랙을 애니메이션의 특정 순간으로 점프하도록 설정할 수 있습니다.

시간 위치는 애니메이션의 특정 지점으로 이동하도록 설정할 수 있지만, AnimationTrack가 재생되어야만 그렇게 할 수 있습니다.또한 AnimationTrack:AdjustSpeed() 와 결합하여 원하는 지점에서 애니메이션을 동결할 수 있습니다(속도를 0으로 설정).

코드 샘플

The following code sample includes two functions that demonstrate how AdjustSpeed and TimePosition can be used to freeze an animation at a particular point.

The first function freezes an animation at a particular point in time (defined in seconds). The second freezes at it at a percentage (between 0 or 100) by multiplying the percentage by the track length.

As TimePosition can not be used when an AnimationTrack is not playing, the functions check to make sure the animation is playing before proceeding.

Freeze Animation at Position

function freezeAnimationAtTime(animationTrack, timePosition)
if not animationTrack.IsPlaying then
-- Play the animation if it is not playing
animationTrack:Play()
end
-- Set the speed to 0 to freeze the animation
animationTrack:AdjustSpeed(0)
-- Jump to the desired TimePosition
animationTrack.TimePosition = timePosition
end
function freezeAnimationAtPercent(animationTrack, percentagePosition)
if not animationTrack.IsPlaying then
-- Play the animation if it is not playing
animationTrack:Play()
end
-- Set the speed to 0 to freeze the animation
animationTrack:AdjustSpeed(0)
-- Jump to the desired TimePosition
animationTrack.TimePosition = (percentagePosition / 100) * animationTrack.Length
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
freezeAnimationAtTime(animationTrack, 0.5)
freezeAnimationAtPercent(animationTrack, 50)

WeightCurrent

읽기 전용
복제되지 않음
병렬 읽기

무게가 AnimationTrack에 설정되면 즉시 변경되지 않고 WeightCurrent에서 AnimationTrack.WeightTarget로 이동합니다.이 작업을 수행하는 데 걸리는 시간은 애니메이션이 재생되거나 무게가 조정될 때 제공된 fadeTime 매개 변수에 의해 결정됩니다.

WeightCurrent는 AnimationTrack.WeightTarget에 대해 확인하여 원하는 무게에 도달했는지 확인할 수 있습니다.이러한 값이 둘 다 부동 소수점이기 때문에 == 연산자와의 동일성을 확인해서는 안된다는 점에 유의하십시오.WeightCurrent가 목표 무게에 도달했는지 확인하려면 해당 값 간의 거리가 충분히 작은지 확인하는 것이 좋습니다(아래 코드 샘플 참조).

애니메이션 중량 시스템은 동일한 우선 순위로 플레이하는 AnimationTracks가 어떻게 혼합되는지 결정하는 데 사용됩니다.기본 무게는 하나이며, 무게가 0인 AnimationTrack 에서는 이동이 표시되지 않습니다.시간의 어느 시점에 표시되는 포즈는 모든 Poses 및 각 AnimationTrack의 무게 평균에 의해 결정됩니다.대부분의 경우 블렌딩 애니메이션은 필요하지 않으며 AnimationTrack.Priority 를 사용하는 것이 더 적합합니다.

코드 샘플

This code sample loads two animations onto the local player's Humanoid and demonstrates how the fadeTime paramater in AnimationTrack.Play determines how long it takes for an AnimationTrack's WeightCurrent to reach it's WeightTarget.

As WeightCurrent and WeightTarget are floats the == operator cannot be used to compare, instead it is more appropriate to check that the difference between them is sufficiently small to assume the weight fade has completed.

WeightCurrent and WeightTarget

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation1 = Instance.new("Animation")
animation1.AnimationId = "rbxassetid://507770453"
local animation2 = Instance.new("Animation")
animation2.AnimationId = "rbxassetid://507771019"
task.wait(3) -- arbitrary wait time to allow the character to fall into place
local animationTrack1 = animator:LoadAnimation(animation1)
local animationTrack2 = animator:LoadAnimation(animation2)
animationTrack1.Priority = Enum.AnimationPriority.Movement
animationTrack2.Priority = Enum.AnimationPriority.Action
animationTrack1:Play(0.1, 5, 1)
animationTrack2:Play(10, 3, 1)
local done = false
while not done and task.wait(0.1) do
if math.abs(animationTrack2.WeightCurrent - animationTrack2.WeightTarget) < 0.001 then
print("got there")
done = true
end
end

WeightTarget

읽기 전용
복제되지 않음
병렬 읽기

AnimationTrack.WeightTarget는 AnimationTrack의 현재 무게를 제공하는 읽기 전용 속성입니다.기본값은 1이며 AnimationTrack:Play() , AnimationTrack:Stop() 또는 AnimationTrack:AdjustWeight() 이 호출될 때 설정됩니다.무게가 AnimationTrack에 설정되면 즉시 변경되지 않고 WeightCurrent에서 AnimationTrack.WeightTarget로 이동합니다.이 작업을 수행하는 데 걸리는 시간은 애니메이션이 재생되거나 무게가 조정될 때 제공된 fadeTime 매개 변수에 의해 결정됩니다.

WeightCurrent는 AnimationTrack.WeightTarget에 대해 확인하여 원하는 무게에 도달했는지 확인할 수 있습니다.이러한 값이 둘 다 부동 소수점이기 때문에 == 연산자와의 동일성을 확인해서는 안된다는 점에 유의하십시오.WeightCurrent가 목표 무게에 도달했는지 확인하려면 해당 값 간의 거리가 충분히 작은지 확인하는 것이 좋습니다(아래 코드 샘플 참조).

애니메이션 중량 시스템은 동일한 우선 순위로 플레이하는 AnimationTracks가 어떻게 혼합되는지 결정하는 데 사용됩니다.기본 무게는 하나이며, 무게가 0인 AnimationTrack 에서는 이동이 표시되지 않습니다.시간의 어느 시점에 표시되는 포즈는 모든 Poses 및 각 AnimationTrack의 무게 평균에 의해 결정됩니다.대부분의 경우 블렌딩 애니메이션은 필요하지 않으며 AnimationTrack.Priority 를 사용하는 것이 더 적합합니다.

코드 샘플

This code sample loads two animations onto the local player's Humanoid and demonstrates how the fadeTime paramater in AnimationTrack.Play determines how long it takes for an AnimationTrack's WeightCurrent to reach it's WeightTarget.

As WeightCurrent and WeightTarget are floats the == operator cannot be used to compare, instead it is more appropriate to check that the difference between them is sufficiently small to assume the weight fade has completed.

WeightCurrent and WeightTarget

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation1 = Instance.new("Animation")
animation1.AnimationId = "rbxassetid://507770453"
local animation2 = Instance.new("Animation")
animation2.AnimationId = "rbxassetid://507771019"
task.wait(3) -- arbitrary wait time to allow the character to fall into place
local animationTrack1 = animator:LoadAnimation(animation1)
local animationTrack2 = animator:LoadAnimation(animation2)
animationTrack1.Priority = Enum.AnimationPriority.Movement
animationTrack2.Priority = Enum.AnimationPriority.Action
animationTrack1:Play(0.1, 5, 1)
animationTrack2:Play(10, 3, 1)
local done = false
while not done and task.wait(0.1) do
if math.abs(animationTrack2.WeightCurrent - animationTrack2.WeightTarget) < 0.001 then
print("got there")
done = true
end
end

메서드

AdjustSpeed

()

이 함수는 애니메이션의 AnimationTrack.Speed를 변경합니다.속도에 대한 양의 값은 애니메이션을 앞으로 재생하고, 음의 값은 뒤로 재생하며, 0은 일시 중지합니다.

애니메이션 트랙의 초기 속도는 AnimationTrack:Play()에서 매개 변수로 설정됩니다.그러나 트랙의 속도는 재생 중에 AdjustSpeed를 사용하여 변경할 수 있습니다.속도가 1과 같을 때 애니메이션이 완료하는 데 걸리는 시간은 AnimationTrack.Length (초)와 같습니다.

조정되면 트랙이 재생하는 데 걸리는 실제 시간을 길이를 속도로 나누어 계산할 수 있습니다. 속도는 단위가 없는 양입니다.

속도를 사용하여 동일한 애니메이션의 길이를 다른 게임플레이 이벤트(예: 능력 재충전)에 연결할 수 있으면서도 동일한 애니메이션의 다른 변형을 업로드할 필요가 없습니다.

매개 변수

speed: number

애니메이션의 재생 속도를 변경할 값.

기본값: 1

반환

()

코드 샘플

The following function will play an AnimationTrack for a specific duration. This is done by changing the speed of the animation to the length of the animation divided by the desired playback duration. This could be used in situations where a developer wants to play a standard animation for different duration (for example, recharging different abilities).

Playing Animation for a Specific Duration

local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)

In this example a player and an animation is loaded. The Length of an AnimationTrack determines how long the track would take to play if the speed is at 1. If the speed is adjusted, then the actual time it will take a track to play can be computed by dividing the length by the speed.

Animation Speed

local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507770453"
ContentProvider:PreloadAsync({ animation })
local animationTrack = animator:LoadAnimation(animation)
local normalSpeedTime = animationTrack.Length / animationTrack.Speed
animationTrack:AdjustSpeed(3)
local fastSpeedTime = animationTrack.Length / animationTrack.Speed
print("At normal speed the animation will play for", normalSpeedTime, "seconds")
print("At 3x speed the animation will play for", fastSpeedTime, "seconds")

AdjustWeight

()

선택적인 fadeTime 매개 변수로 애니메이션의 무게를 변경하여 AnimationTrack.WeightCurrent에서 AnimationTrack.WeightTarget에 도달하는 데 걸리는 시간을 결정합니다.

무게가 AnimationTrack에 설정되면 즉시 변경되지 않고 WeightCurrent에서 AnimationTrack.WeightTarget로 이동합니다.이 작업을 수행하는 데 걸리는 시간은 애니메이션이 재생되거나 무게가 조정될 때 제공된 fadeTime 매개 변수에 의해 결정됩니다.

WeightCurrent는 AnimationTrack.WeightTarget에 대해 확인하여 원하는 무게에 도달했는지 확인할 수 있습니다.이러한 값이 둘 다 부동 소수점이기 때문에 == 연산자와의 동일성을 확인해서는 안된다는 점에 유의하십시오.WeightCurrent가 목표 무게에 도달했는지 확인하려면 해당 값 간의 거리가 충분히 작은지 확인하는 것이 좋습니다(아래 코드 샘플 참조).

애니메이션 중량 시스템은 동일한 우선 순위로 플레이하는 AnimationTracks가 어떻게 혼합되는지 결정하는 데 사용됩니다.기본 무게는 하나이며, 무게가 0인 AnimationTrack 에서는 이동이 표시되지 않습니다.시간의 어느 시점에 표시되는 포즈는 모든 Poses 및 각 AnimationTrack의 무게 평균에 의해 결정됩니다.실제 애니메이션 믹싱의 예는 아래를 참조하십시오.대부분의 경우 블렌딩 애니메이션은 필요하지 않으며 AnimationTrack.Priority 를 사용하는 것이 더 적합합니다.

매개 변수

weight: number

애니메이션을 변경할 무게.

기본값: 1
fadeTime: number

애니메이션이 이전 무게와 새 무게 사이에서 사라질 시간의 기간.

기본값: 0.100000001

반환

()

코드 샘플

This code sample includes a function that changes the weight of an AnimationTrack and yields until the weight has changed to the new target weight.

The purpose of this sample is to demonstrate how the fadeTime parameter of AnimationTrack.AdjustWeight works. In most cases, if a developer wishes to yield over the fadeTime it is recommended they use wait(fadeTime).

AnimationTrack Change Weight

local function changeWeight(animationTrack, weight, fadeTime)
animationTrack:AdjustWeight(weight, fadeTime)
local startTime = tick()
while math.abs(animationTrack.WeightCurrent - weight) > 0.001 do
task.wait()
end
print("Time taken to change weight " .. tostring(tick() - startTime))
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
changeWeight(animationTrack, 0.6, 1)

GetMarkerReachedSignal

이 함수는 event 이벤트와 유사하게 반환하지만, 지정된 AnimationTrack.KeyframeReached 가 한 번만 발생하고 특정 KeyframeMarker 가 한 번만 발생하며, animation 에서만 발생합니다.차이는 이벤트가 발생하는 시기를 더 세밀하게 제어할 수 있게 합니다.

이 함수를 사용하는 방법에 대해 자세히 알아보려면 애니메이션 이벤트 기사에서 애니메이션 편집기 항목을 참조하십시오.

키프레임에 대해 더 알아보기

Keyframe 이름은 애니메이션을 만들거나 편집할 때 Roblox 애니메이션 편집기에서 설정할 수 있습니다.그러나 플레이하기 전에 기존 애니메이션에서 Script에 의해 설정될 수는 없습니다.

Keyframe 이름은 유일해야 하지 않습니다.예를 들어, Animation 에 "EmitParticles"라는 세 가지 키프레임이 있으면, 이 함수에서 반환된 연결된 이벤트는 이 키프레임 중 하나가 도달할 때마다 발생합니다.

참조하세요:

매개 변수

name: string

신호의 이름이 KeyFrameMarker 생성되고 있습니다.

기본값: ""

반환

애니메이션이 생성된 KeyFrameMarker 에 도달했을 때 생성되고 발사된 신호.

코드 샘플

This LocalScript code waits for the local player's Humanoid object to load, then it creates a new Animation instance with the proper Animation.AnimationId. The animation is then loaded onto the humanoid, creating an AnimationTrack, and the track is played with AnimationTrack:Play(). Following that, the AnimationTrack:GetMarkerReachedSignal() function detects when the "KickEnd" marker is hit.

Listening to Keyframe Markers

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.Character:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Create new "Animation" instance
local kickAnimation = Instance.new("Animation")
-- Set its "AnimationId" to the corresponding animation asset ID
kickAnimation.AnimationId = "rbxassetid://2515090838"
-- Load animation onto the humanoid
local kickAnimationTrack = humanoid:LoadAnimation(kickAnimation)
-- Play animation track
kickAnimationTrack:Play()
-- If a named event was defined for the animation, connect it to "GetMarkerReachedSignal()"
kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
print(paramString)
end)

GetTargetInstance

매개 변수

name: string
기본값: ""

반환

GetTargetNames


반환

GetTimeOfKeyframe

지정된 이름의 첫 번째 Keyframe 의 시간 위치를 AnimationTrack 에 반환합니다.여러 개의 Keyframes가 동일한 이름을 공유하면 애니메이션에서 가장 먼저 나오는 것을 반환합니다.

이 함수는 유효하지 않은 키프레임 이름(예를 들어 존재하지 않는 것)을 사용하거나 기본 Animation가 아직 로드되지 않은 경우 오류를 반환합니다.이를 해결하려면 올바른 키 프레임 이름만 사용하고 이 함수를 호출하기 전에 애니메이션이 로드되었는지 확인하십시오.

애니메이션이 로드되었는지 확인하려면 AnimationTrack.Length가 0보다 크다는 것을 확인하십시오.

매개 변수

keyframeName: string

찾을 수 있는 Keyframe와 관련된 이름.

기본값: ""

반환

시간, 초, Keyframe 정상 재생 속도에서 발생합니다.

코드 샘플

This sample includes a function that will jump to the first keyframe of a specified name in an AnimationTrack.

As AnimationTrack.TimePosition cannot be set while the animation is not playing the function first checks to see if the animation is playing.

This sample will only work once an Animation has loaded.

Jump To Keyframe

local function jumpToKeyframe(animationTrack, keyframeName)
local timePosition = animationTrack:GetTimeOfKeyframe(keyframeName)
if not animationTrack.IsPlaying then
animationTrack:Play()
end
animationTrack.TimePosition = timePosition
end
local ANIMATION_ID = 0
local KEYFRAME_NAME = "Test"
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://" .. ANIMATION_ID
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
jumpToKeyframe(animationTrack, KEYFRAME_NAME)

Play

()

When AnimationTrack:Play() 가 호출되면 트랙의 애니메이션이 재생을 시작하고 애니메이션의 무게가 0에서 지정된 무게로 증가합니다(기본값은 1, 지정된 페이드타임은 0.1).

AnimationTrack 가 재생할 속도는 속도 매개 변수(기본값은 1)에 의해 결정됩니다.속도가 1과 같을 때 트랙이 완료하는 데 걸리는 시간은 트랙의 AnimationTrack.Length 속성과 같습니다.예를 들어, 속도 2는 트랙이 2배 더 빨리 재생되도록 합니다.

애니메이션의 무게와 속도도 애니메이션이 재생을 시작한 후 AnimationTrack:AdjustWeight()AnimationTrack:AdjustSpeed() 메서드를 사용하여 변경할 수 있습니다.

개발자가 AnimationTrack.TimePosition를 사용하여 특정 지점에서 애니메이션을 시작하려는 경우, 이것이 완료되기 전에 애니메이션이 재생되는 것이 중요합니다.

매개 변수

fadeTime: number

애니메이션의 무게가 사라져야 할 시간 길이.

기본값: 0.100000001
weight: number

애니메이션이 재생될 무게입니다.

기본값: 1
speed: number

애니메이션의 재생 속도.

기본값: 1

반환

()

코드 샘플

The following function will play an AnimationTrack for a specific duration. This is done by changing the speed of the animation to the length of the animation divided by the desired playback duration. This could be used in situations where a developer wants to play a standard animation for different duration (for example, recharging different abilities).

Playing Animation for a Specific Duration

local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)

The following code sample includes two functions that demonstrate how AdjustSpeed and TimePosition can be used to freeze an animation at a particular point.

The first function freezes an animation at a particular point in time (defined in seconds). The second freezes at it at a percentage (between 0 or 100) by multiplying the percentage by the track length.

As TimePosition can not be used when an AnimationTrack is not playing, the functions check to make sure the animation is playing before proceeding.

Freeze Animation at Position

function freezeAnimationAtTime(animationTrack, timePosition)
if not animationTrack.IsPlaying then
-- Play the animation if it is not playing
animationTrack:Play()
end
-- Set the speed to 0 to freeze the animation
animationTrack:AdjustSpeed(0)
-- Jump to the desired TimePosition
animationTrack.TimePosition = timePosition
end
function freezeAnimationAtPercent(animationTrack, percentagePosition)
if not animationTrack.IsPlaying then
-- Play the animation if it is not playing
animationTrack:Play()
end
-- Set the speed to 0 to freeze the animation
animationTrack:AdjustSpeed(0)
-- Jump to the desired TimePosition
animationTrack.TimePosition = (percentagePosition / 100) * animationTrack.Length
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
freezeAnimationAtTime(animationTrack, 0.5)
freezeAnimationAtPercent(animationTrack, 50)

SetTargetInstance

()

매개 변수

name: string
기본값: ""
target: Instance
기본값: ""

반환

()

Stop

()

AnimationTrack를 중지합니다.호출되면 애니메이션의 무게가 선택적 fadeTime 매개 변수에 의해 지정된 기간 동안 0으로 이동합니다.예를 들어, Stop() 가 의 fadeTime2 와 함께 호출되면 트랙의 무게가 0에 도달하고 효과가 완전히 종료데 2초가 걸립니다.애니메이션의 초기 무게에 관계없이 이 경우가 될 것입니다.

이 효과를 무효화하고 애니메이션을 즉시 종료하기 위해 의 를 사용하는 것은 권장되지 않으며, 이는 조인트가 동결되기 때문입니다.즉시 종료해야 하는 경우, 리그에서 Motor.MaxVelocityMotor6Ds 가 충분히 높아서 제대로 스냅되도록 하십시오.

매개 변수

fadeTime: number

애니메이션 무게가 사라질 시간(초), 즉 애니메이션 무게가 사라질 시간.

기본값: 0.100000001

반환

()

코드 샘플

This code sample includes a function that stops an AnimationTrack with a specific fadeTime, and yields until the fade is completed and the weight of the AnimationTrack is equal to zero.

The purpose of this sample is to demonstrate how the fadeTime parameter of AnimationTrack.Stop works. In most cases, if a developer wishes to yield over the fadeTime it is recommended they use wait(fadeTime).

AnimationTrack Stop

local function fadeOut(animationTrack, fadeTime)
animationTrack:Stop(fadeTime)
local startTime = tick()
while animationTrack.WeightCurrent > 0 do
task.wait()
end
local timeTaken = tick() - startTime
print("Time taken for weight to reset: " .. tostring(timeTaken))
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
fadeOut(animationTrack, 1)

이벤트

DidLoop

이 이벤트는 루프된 AnimationTrack 가 루프를 완료할 때마다 다음 업데이트에서 발생합니다.

현재 비루프 애니메이션 트랙의 정확한 끝에서도 발사할 수 있지만 이 동작은 의존해서는 안됩니다.


코드 샘플

The function in this code sample will play an AnimationTrack on a loop, for a specific number of loops, before stopping the animation.

In some cases the developer may want to stop a looped animation after a certain number of loops have completed, rather than after a certain amount of time. This is where the DidLoop event can be used.

Play AnimationTrack for a Number of Loops

local function playForNumberLoops(animationTrack, number)
animationTrack.Looped = true
animationTrack:Play()
local numberOfLoops = 0
local connection = nil
connection = animationTrack.DidLoop:Connect(function()
numberOfLoops = numberOfLoops + 1
print("loop: ", numberOfLoops)
if numberOfLoops >= number then
animationTrack:Stop()
connection:Disconnect() -- it's important to disconnect connections when they are no longer needed
end
end)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playForNumberLoops(animationTrack, 5)

Ended

세계에서 아무것도 이동하는 것이 완전히 끝났을 때 AnimationTrack가 발생합니다.애니메이션이 재생을 마쳤고, "페이드 아웃"이 완료되었으며, 주제가 중립 자세에 있습니다.

이를 사용하여 애니메이션 트랙의 주제가 중립 자세로 돌아와 AnimationTrack 에 영향을 받지 않거나 AnimationTrack 를 정리할 수 있습니다.또는 연결된 모든 것.


코드 샘플

The function in this code sample plays an animationTrack and yields until it has stopped and ended, printing at each step along the way.

AnimationTrack Ended

local InsertService = game:GetService("InsertService")
local Players = game:GetService("Players")
-- Create an NPC model to animate.
local npcModel = Players:CreateHumanoidModelFromUserId(129687796)
npcModel.Name = "JoeNPC"
npcModel.Parent = workspace
npcModel:MoveTo(Vector3.new(0, 15, 4))
local humanoid = npcModel:WaitForChild("Humanoid")
-- Load an animation.
local animationModel = InsertService:LoadAsset(2510238627)
local animation = animationModel:FindFirstChildWhichIsA("Animation", true)
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
-- Connect to Stopped event. This fires when animation stops of
-- it's own accord, or we explicitly call Stop.
animationTrack.Stopped:Connect(function()
print("Animation stopped")
end)
-- Connect to Ended event. This fires when when animation is completely
-- finished affecting the world. In this case it will fire 3 seconds
-- after we call animationTrack:Stop because we pass in a 3
-- second fadeOut.
animationTrack.Ended:Connect(function()
print("Animation ended")
animationTrack:Destroy()
end)
-- Run, give it a bit to play, then stop.
print("Calling Play")
animationTrack:Play()
task.wait(10)
print("Calling Stop")
animationTrack:Stop(3)

KeyframeReached

재생 시 모든 경우 AnimationTrack 의 플레이백이 기본 이름 - "키프레임"을 가지지 않는 Keyframe 에 도달하면 발생합니다.

이 이벤트를 통해 개발자는 애니메이션의 미리 정의된 지점에서 코드를 실행할 수 있습니다(Keyframe 이름에 의해 설정됨).이렇게 하면 애니메이션의 다른 지점에서 Sounds 또는 ParticleEffects 을 추가하여 Roblox 애니메이션의 기본 기능이 확장될 수 있습니다.

Keyframe 이름은 유일해야 하지 않습니다.예를 들어, 애니메이션에 "파편"이라는 세 가지 키프레임이 있으면 키프레임 도달 이벤트가 이러한 키프레임 중 하나가 도달할 때마다 발생합니다.

Keyframe 이름은 애니메이션을 만들거나 편집할 때 Roblox 애니메이션 편집기에서 설정할 수 있습니다.그러나 플레이하기 전에 기존 애니메이션에서 Script에 의해 설정될 수 없습니다.

매개 변수

keyframeName: string

Keyframe에 도달한 이름.


Stopped

플레이가 끝날 때마다 AnimationTrack 발사합니다.

이 이벤트는 여러 용도가 있습니다.예를 들어, 연속 애니메이션을 차례로 재생하기 전에 중지될 때까지 기다리려면 AnimationTrack를 사용할 수 있습니다(예: 애니메이션 시리즈를 연결하여 서로 플레이하기 전에 중지).애니메이션 재생 중에 생성된 모든 Instances를 정리하는 데도 사용할 수 있습니다.


코드 샘플

The function in this code sample will play an animationTrack and yield until it has stopped, before printing.

AnimationTrack Stopped

local function yieldPlayAnimation(animationTrack, fadeTime, weight, speed)
animationTrack:Play(fadeTime, weight, speed)
animationTrack.Stopped:Wait()
print("Animation has stopped")
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
yieldPlayAnimation(animationTrack, 1, 0.6, 1)