Garry's Mod Wiki

Revision Difference

BaseAnimatingOverlay#568330

<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. <page>NextBot</page>s, most <page>NPC</page>s and <page>Player</page>s are `BaseAnimatingOverlay` entities. Only <page>Scripted Entities</page> of the `anim` type are `BaseAnimatingOverlay`. ⤶ <page>Player</page>s follow a different layer implementation. Layers for players aren't automatically networked. The layer functions special to Player entity must be used rather than <page>Entity</page> functions to add the layer. The call must be networked; for `SERVER` to update the hitboxes properly and for `CLIENT` for the animation to be seen. For other entity types, added layers automatically get networked. ⤶ <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 functions special to <page>Player</page>⤶ * <page>Player:AddVCDSequenceToGestureSlot</page>⤶ * <page>Player:AnimResetGestureSlot</page>⤶ * <page>Player:AnimRestartGesture</page>⤶ * <page>Player:AnimSetGestureSequence</page>⤶ * <page>Player:AnimSetGestureWeight</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> * <page>Entity:SetLayerAutokill</page> * Other functions * <page>Entity:FindGestureLayer</page> * <page>Entity:FindGestureSequenceLayer</page> * <page>Entity:IsPlayingGesture</page> * <page>Entity:RestartGesture</page> * <page>Entity:RemoveGesture</page> * <page>Entity:RemoveAllGestures</page> * <page>Entity:RemoveLayer</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>