Created
February 9, 2013 00:00
-
-
Save friesencr/4743009 to your computer and use it in GitHub Desktop.
leadwerks character animation template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("scripts/class") | |
require("scripts/math/math") | |
require("Scripts/constants/engine_const") | |
local class=CreateClass(...) | |
function class:CreateObject(model) | |
local object=self.super:CreateObject(model) | |
local animation_data = { | |
walk = { | |
start = 50, | |
frames = 23, | |
multiplier = 1 | |
}, | |
idle = { | |
start = 0, | |
frames = 44, | |
multiplier = 1 | |
}, | |
strafe = { | |
start = 75, | |
frames = 117 - 75, | |
multiplier = 3 | |
}, | |
run = { | |
start = 125, | |
frames = 142 - 125, | |
multiplier = 1 | |
}, | |
run_strafe = { | |
start = 75, | |
frames = 117 - 75, | |
multiplier = 5 | |
}, | |
jump = { | |
start = 150, | |
frames = 176 - 150, | |
multiplier = 1 | |
}, | |
land = { | |
start = 210, | |
frames = 214 - 210, | |
multiplier = 1 | |
} | |
} | |
local current_frame | |
local animation_state | |
local animation_start_time = AppTime() | |
local current_animation = animation_data['idle'] | |
function object:Update() | |
local ca = current_animation | |
local time = AppTime() - animation_start_time | |
local frame = (( time / 60 ) % (ca.frames/ca.multiplier)) * ca.multiplier + ca.start | |
self.model:Animate(frame, 0.2,0,1) | |
end | |
function SetAnimationState(state) | |
animation_state = state | |
animation_start_time = AppTime() | |
current_animation = animation_data[state] | |
end | |
function object:ReceiveMessage(message, extra) | |
if message == 'idle' then object:Idle() | |
elseif message == 'walk' then object:Walk() | |
elseif message == 'run' then object:Run() | |
elseif message == 'jump' then object:Jump() | |
elseif message == 'land' then object:Land() | |
elseif message == 'strafe' then object:Strafe() | |
elseif message == 'run_strafe' then object:RunStrafe() end | |
end | |
function object:Walk() | |
if animation_state ~= 'walk' then SetAnimationState('walk') end | |
end | |
function object:Idle() | |
if animation_state ~= 'idle' then SetAnimationState('idle') end | |
end | |
function object:Run() | |
if animation_state ~= 'run' then SetAnimationState('run') end | |
end | |
function object:Strafe() | |
if animation_state ~= 'strafe' then SetAnimationState('strafe') end | |
end | |
function object:RunStrafe() | |
if animation_state ~= 'strafe' then SetAnimationState('strafe') end | |
end | |
function object:Land() | |
if animation_state ~= 'land' then SetAnimationState('land') end | |
end | |
function object:Jump() | |
if animation_state ~= 'jump' then SetAnimationState('jump') end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment