PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

TimePosition

AnimationTrack

float

Returns the position in time in seconds that an AnimationTrack is through playing its source animation. Can be set to make the track jump to a specific moment in the animation.

TimePosition can be set to go to a specific point in the animation, but the AnimationTrack must be playing to do so. It can also be used in combination with AnimationTrack/AdjustSpeed to freeze the animation at a desired point (by setting speed to 0).


Code Samples


Freeze Animation at Position

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.

function freezeAnimationAtTime(animationTrack, timePosition)
	-- Set the speed to 0 to freeze the animation
	animationTrack:AdjustSpeed(0)
	if not animationTrack.IsPlaying then
		-- Play the animation if it is not playing
		animationTrack:Play() 
	end
	-- Jump to the desired TimePosition
	animationTrack.TimePosition = timePosition
end

function freezeAnimationAtPercent(animationTrack, percentagePosition)
	-- Set the speed to 0 to freeze the animation
	animationTrack:AdjustSpeed(0)
	if not animationTrack.IsPlaying then
		-- Play the animation if it is not playing
		animationTrack:Play() 
	end
	-- Jump to the desired TimePosition
	animationTrack.TimePosition = (percentagePosition / 100) * animationTrack.Length
end