Garry's Mod Wiki

Revision Difference

BaseAnimatingOverlay#564940

<title>Animation Layer​s (BaseAnimatingOverlay)</title>⤶ <cat>Dev.Entities</cat> Entities based on `BaseAnimatingOverlay` are capable of layering animations. <page>NextBot</page>s and <page>Player</page>s are `BaseAnimatingOverlay` entities. Only <page>Scripted Entities</page> of the `anim` type are `BaseAnimatingOverlay`. <note>Playing gestures/creating new layers on <page>NextBot</page>s may not work correctly unless done in the <page>NEXTBOT:BehaveUpdate</page> hook.</note> The following functions can only be used on **BaseAnimatingOverlay** entities: * Layer creation functions * <page>Entity:AddGesture</page> * <page>Entity:AddGestureSequence</page> * <page>Entity:AddLayeredSequence</page> * Layer manipulation functions * <page>Entity:IsValidLayer</page> * <page>Entity:SetLayerDuration</page> * <page>Entity:GetLayerDuration</page> * <page>Entity:SetLayerCycle</page> * <page>Entity:GetLayerCycle</page> * <page>Entity:SetLayerPlaybackRate</page> * <page>Entity:SetLayerWeight</page> * <page>Entity:GetLayerWeight</page> * <page>Entity:SetLayerBlendIn</page> * <page>Entity:SetLayerBlendOut</page> * <page>Entity:SetLayerLooping</page> * Other functions * <page>Entity:IsPlayingGesture</page> * <page>Entity:RestartGesture</page> * <page>Entity:RemoveGesture</page> * <page>Entity:RemoveAllGestures</page> <example> <description> Example usage of layers on a `anim` type SENT. </description> <code> AddCSLuaFile() DEFINE_BASECLASS( "base_gmodentity" ) ENT.PrintName = "Example Animated Overlay" ENT.AutomaticFrameAdvance = true function ENT:Initialize() if ( SERVER ) then -- Basic set up - a model with animations and physics mode so it doesn't fall over for demonstration self:SetModel( "models/alyx.mdl" ) self:PhysicsInit( SOLID_OBB ) self:ResetSequence( "walk_all" ) -- Base sequence, walking self:SetPoseParameter( "move_yaw", 90 ) -- Affects how the base sequence looks -- Overlayed sequence on top of base animation, move the head -- false at the end to not kill the animation after it plays once. self.LayerID = self:AddGestureSequence( self:LookupSequence( "a_bg_lookupright" ), false ) self:SetLayerLooping( self.LayerID, true ) -- Loop the layer end end function ENT:Think() if ( SERVER ) then -- Do any logic with layers here, play them, stop them, etc. -- Make sure the animation is smooth self:NextThink( CurTime() ) return true end end </code> </example>