Gamemode.UpdateAnimation

From GMod Wiki

Jump to: navigation, search
Event Hook
Hook NameUpdateAnimation
SyntaxGM:UpdateAnimation( Player )
DescriptionUsed to update the animation states (e.g: pose parameters) of a player each frame/tick/render(?).
ReturnsNil
Lua StateNewerShared.png
BBCode[b][url=wiki.garrysmod.com/?title=Gamemode.UpdateAnimation]Gamemode.UpdateAnimation [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionThe default Base Gamemode UpdateAnimation function used to set a player's pose parameter when they are in a seat. Usage is the same as the hook.
Used onNewerClient.png
Code
 
/*---------------------------------------------------------
   Name: gamemode:UpdateAnimation( )
   Desc: Animation updates (pose params etc) should be done here
---------------------------------------------------------*/
function GM:UpdateAnimation( ply, velocity, maxseqgroundspeed )    
    local len2d = velocity:Length2D()
    local rate = 1.0
 
    if len2d > 0.5 then
            rate =  ( len2d / maxseqgroundspeed )
    end
 
    rate = math.min(rate, 2)
 
    ply:SetPlaybackRate( rate )
 
    if ( ply:InVehicle() ) then
        local Vehicle =  ply:GetVehicle()
 
        // We only need to do this clientside..
        if ( CLIENT ) then
            //
            // This is used for the 'rollercoaster' arms
            //
            local Velocity = Vehicle:GetVelocity()
            ply:SetPoseParameter( "vertical_velocity", Velocity.z * 0.01 )
 
            // Pass the vehicles steer param down to the player
            local steer = Vehicle:GetPoseParameter( "vehicle_steer" )
            steer = steer * 2 - 1 // convert from 0..1 to -1..1
            ply:SetPoseParameter( "vehicle_steer", steer  )
        end
 
    end
end
 
OutputThe player's arms will go up based on vertical velocity when they are in a in a vehicle.


Additional Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox