From 8867ca41536a97c687afd10050d8bf3f1b73aafc Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Fri, 2 Jul 2021 17:32:13 +0200 Subject: [PATCH] fix stuck anims in tps character controller script --- Content/scripts/character_controller_tps.lua | 56 ++++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Content/scripts/character_controller_tps.lua b/Content/scripts/character_controller_tps.lua index 16c8b6372..456757bed 100644 --- a/Content/scripts/character_controller_tps.lua +++ b/Content/scripts/character_controller_tps.lua @@ -138,6 +138,34 @@ Character = { if( input.Press(string.byte('J')) or input.Press(KEYBOARD_BUTTON_SPACE) or input.Press(GAMEPAD_BUTTON_2) ) then self:Jump(2000) end + + -- state and animation update + if(self.state == self.states.STAND) then + scene.Component_GetAnimation(self.walk_anim).Stop() + local anim = scene.Component_GetAnimation(self.idle_anim) + anim.Play() + anim.SetAmount(math.lerp(anim.GetAmount(), 1, 0.1)) + if(self.state ~= self.state_prev) then + anim.SetAmount(0) + end + elseif(self.state == self.states.WALK) then + scene.Component_GetAnimation(self.idle_anim).Stop() + local anim = scene.Component_GetAnimation(self.walk_anim) + anim.Play() + anim.SetAmount(math.lerp(anim.GetAmount(), 1, 0.1)) + if(self.state ~= self.state_prev) then + anim.SetAmount(0) + end + elseif(self.state == self.states.JUMP) then + scene.Component_GetAnimation(self.walk_anim).Stop() + local anim = scene.Component_GetAnimation(self.idle_anim) + anim.Play() + anim.SetAmount(math.lerp(anim.GetAmount(), 1, 0.1)) + if(self.state ~= self.state_prev) then + anim.SetAmount(0) + end + end + self.state_prev = self.state -- Camera target control: @@ -168,34 +196,6 @@ Character = { local model_transform = scene.Component_GetTransform(self.model) local target_transform = scene.Component_GetTransform(self.target) - -- state and animation update - if(self.state == self.states.STAND) then - scene.Component_GetAnimation(self.walk_anim).Stop() - local anim = scene.Component_GetAnimation(self.idle_anim) - anim.Play() - anim.SetAmount(math.lerp(anim.GetAmount(), 1, 0.1)) - if(self.state ~= self.state_prev) then - anim.SetAmount(0) - end - elseif(self.state == self.states.WALK) then - scene.Component_GetAnimation(self.idle_anim).Stop() - local anim = scene.Component_GetAnimation(self.walk_anim) - anim.Play() - anim.SetAmount(math.lerp(anim.GetAmount(), 1, 0.1)) - if(self.state ~= self.state_prev) then - anim.SetAmount(0) - end - elseif(self.state == self.states.JUMP) then - scene.Component_GetAnimation(self.walk_anim).Stop() - local anim = scene.Component_GetAnimation(self.idle_anim) - anim.Play() - anim.SetAmount(math.lerp(anim.GetAmount(), 1, 0.1)) - if(self.state ~= self.state_prev) then - anim.SetAmount(0) - end - end - self.state_prev = self.state - -- apply force: self.velocity = vector.Add(self.velocity, vector.Multiply(self.force, 0.016)) self.force = Vector(0,0,0,0)