재생 및 복제에 책임이 있는 주요 클래스 Animations .모든 플레이 복제 AnimationTracks는 인스턴스 Animator를 통해 처리됩니다.
또한 애니메이션 편집기 와 애니메이션 사용 을 참조하여 게임에 미리 빌드된 또는 사용자 지정 애니메이션을 만들고 추가하는 방법을 배우십시오.
요약
속성
메서드
부품 간의 상대 속도를 계산하고 Motor6D.Part1에 적용합니다.이러한 상대 속도 계산과 할당은 제공된 순서대로 발생합니다.
현재 재생 목록을 AnimationTracks 로 반환합니다.
로드 Animation 를 다른 Animator 에 업로드하여 반환합니다 AnimationTrack .
모든 재생 에 로드된 모든 플레이 에 오프셋을 적용하여 모델에 연결된 에 대해 오프셋을 적용합니다.명령줄이나 플러그인에서만 사용할 수 있습니다.
이벤트
애니메이터가 애니메이션 트랙 재생을 시작할 때 발생합니다.
속성
메서드
ApplyJointVelocities
현재 플레이 중인 AnimationTracks 세트와 현재 플레이 시간과 플레이 속도를 고려하여 부품 간의 상대 속도를 계산하고 Motor6D.Part1(Animator "자식" 부품으로 간주되는 부품)에 적용합니다.이러한 상대 속도 계산과 할당은 제공된 순서대로 발생합니다.
이 메서드는 조인트의 부품 중 하나가 현재 동일한 어셈블리의 일부인 경우, 예를 들어 모터나 접합으로 직접 또는 간접적으로 연결되어 있는 경우 특정 조인트에 속도를 적용하지 않습니다.
이 메서드는 조인트를 비활성화하거나 제거하지 않습니다.이 메서드를 호출하기 전에 조립에서 강성 조인트를 비활성화하거나 제거해야 합니다.
주어진 Motor6Ds 는 DataModel 의 후손이 되어야 하지 않습니다.이 메서드를 호출하기 전에 DataModel에서 조인을 제거하는 것이 지원됩니다.
매개 변수
반환
LoadAnimation
이 함수는 지정된 Animation 를 이 Animator 에 로드하여 재생 가능한 AnimationTrack 을 반환합니다.클라이언트가 네트워크 소유권을 가진 모델 내에서 Animator 호출할 때, 예를 들어 로컬 플레이어의 캐릭터 또는 BasePart:SetNetworkOwner() 에서, 이 함수는 서버에 대한 애니메이션도 로드합니다.
를 호출하기 전에 에 있어야 하며, 그렇지 않으면 서비스를 검색하고 오류를 발생시킬 수 없습니다.
이 함수를 유사하게 이름이 지정된 Humanoid:LoadAnimation() 및 AnimationController:LoadAnimation() 함수 대신 직접 사용해야 합니다.이들은 이 함수의 사용되지 않는 프록시이며, 존재하지 않으면 Animator 을 생성합니다; 주의하지 않으면 복제 문제가 발생할 수 있습니다.
클라이언트 또는 서버에서 애니메이션 로드
AnimationTracks가 올바르게 복제되려면 클라이언트나 서버에서 언제 로드해야 하는지 알아야 합니다.
가 플레이어의 또는 의 후손인 경우, 해당 플레이어의 클라이언트에서 시작된 애니메이션이 서버와 다른 클라이언트로 복제됩니다.
가 플레이어 캐릭터의 후손이 아니면 그 애니메이션은 복제하기 위해 서버에서 로드되고 시작되어야 합니다.
Animator 개체는 서버에서 처음 생성되어 애니메이션 복제가 작동하도록 클라이언트에 복제해야 합니다.로컬에 Animator 가 생성되고 해당 AnimationTracks 로드되면 Animator 가 복제되지 않습니다.
매개 변수
반환
StepAnimations
모든 재생 에 로드된 모든 플레이 에 오프셋을 적용하여 모델에 연결된 에 대해 오프셋을 적용합니다.명령줄이나 플러그인에서만 사용할 수 있습니다.
deltaTime 매개 변수는 애니메이션의 진행률에 증가할 초 수를 결정합니다.일반적으로 이 함수는 루프에서 호출되어 애니메이션의 길이를 미리 봅니다(예제 참조).
애니메이션이 재생을 중지하면 모델의 관절이 원래 위치로 수동으로 재설정해야 합니다(예제 참조).
이 함수는 게임이 실행되지 않을 때 재생을 시뮬레이션하기 위해 사용됩니다 Animations .이렇게 하면 스크립트 실행과 같은 게임 실행의 결과 없이 애니메이션을 미리 볼 수 있습니다.게임이 실행되는 동안 또는 Scripts 또는 LocalScripts 에서 함수가 호출되면 오류가 반환됩니다.
자체 사용자 지정 애니메이션 편집기를 디자인하는 개발자는 공식 Roblox 애니메이션 편집기 플러그인이 사용하는 방법이기 때문에 이 함수를 사용하여 애니메이션을 미리 보는 것이 좋습니다.
매개 변수
초 단위 애니메이션 재생에 증가할 시간 수입니다.
반환
코드 샘플
This code sample includes a function that can be used to preview an Animation on a Model in Roblox Studio, without needing to run the game. It utilizes the Animator.StepAnimations function, which is the same method the official Roblox Animation Editor uses.
local RunService = game:GetService("RunService")
local function studioPreviewAnimation(model, animation)
-- find the AnimationController and Animator
local animationController = model:FindFirstChildOfClass("Humanoid")
or model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animationController or not animator then
return
end
-- load the Animation to create an AnimationTrack
local track = animationController:LoadAnimation(animation)
track:Play()
-- preview the animation
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- stop the animation
track:Stop(0)
animator:StepAnimations(0)
-- reset the joints
for _, descendant in pairs(model:GetDescendants()) do
if descendant:IsA("Motor6D") then
local joint = descendant
joint.CurrentAngle = 0
joint.Transform = CFrame.new()
end
end
end
local character = script.Parent
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
studioPreviewAnimation(character, animation)