cassius Posted August 28, 2015 Share Posted August 28, 2015 I am struggling to get a "die" animation working properly. My routine works for some characters but not for others. Anyone got some code I could look at? c++ preffered but lua ok too. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
tjheldna Posted August 29, 2015 Share Posted August 29, 2015 This is taken from my code, obviously it wont just work if you copy paste but it might help lead you in the right direction. Hope this helps. void GameCharacter::SetAnimationSequence(float blendTime) { blendStart = Time::GetCurrent(); blendFinish = blendStart + blendTime; } void MagicUser::CharacterAnimate(long sequence) { GameCharacter::CharacterAnimate(sequence); entity->LockMatrix(); switch (sequence) { case kStateIdle: { if (GetState() != GetPrevState()) SetAnimationSequence(200); float animSpeed = 0.008F; float blend = (Time::GetCurrent() - blendStart) / (blendFinish - blendStart); blend = Math::Min(1.0, blend); frame = (Time::GetCurrent() - blendStart) * animSpeed; entity->SetAnimationFrame(frame, blend, sequence, true); break; } case kStateWalk: { if (GetState() != GetPrevState()) SetAnimationSequence(500); float animSpeed = 0.0327F; float blend = (Time::GetCurrent() - blendStart) / (blendFinish - blendStart); blend = Math::Min(1.0, blend); frame = (Time::GetCurrent() - blendStart) * animSpeed; entity->SetAnimationFrame(frame, blend, sequence, true); //if ((int)(frame) % 5 == 0 || (int)(frame) % 14 == 0) //{ // entity->EmitSound(Sound::Load("Sound/Player/footstep1.wav"), 5); //} break; } case kStateJump: case kStateDoubleJump: { if (GetState() != GetPrevState()) SetAnimationSequence(500); float animSpeed = 0.008F; float blend = (Time::GetCurrent() - blendStart) / (blendFinish - blendStart); blend = Math::Min(1.0, blend); frame = (Time::GetCurrent() - blendStart) * animSpeed; entity->SetAnimationFrame(frame, blend, sequence, true); break; } case kStateAttack1: { if (GetState() != GetPrevState()) SetAnimationSequence(500); float animSpeed = 0.05F; float blend = (Time::GetCurrent() - blendStart) / (blendFinish - blendStart); blend = Math::Min(1.0, blend); frame = (Time::GetCurrent() - blendStart) * animSpeed; float length = entity->GetAnimationLength(sequence, true); if (frame >= (length - 1)) { frame = length - 1; SetState(kStateIdle); SetActorFlags(GetActorFlags() & ~kActorAttacking); } entity->SetAnimationFrame(frame, blend, sequence, true); break; } case kStateShoot: { if (GetState() != GetPrevState()) SetAnimationSequence(50); float animSpeed = 0.045F; float blend = (Time::GetCurrent() - blendStart) / (blendFinish - blendStart); blend = Math::Min(1.0, blend); frame = (Time::GetCurrent() - blendStart) * animSpeed; float length = entity->GetAnimationLength(sequence, true); if (frame >= (length - 1)) { frame = length - 1; SetState(kStateIdle); SetActorFlags(GetActorFlags() & ~kActorAttacking); } entity->SetAnimationFrame(frame, blend, sequence, true); break; } case kStateDeath: { if (GetState() != GetPrevState()) SetAnimationSequence(50); float animSpeed = 0.045F; float blend = (Time::GetCurrent() - blendStart) / (blendFinish - blendStart); blend = Math::Min(1.0, blend); frame = (Time::GetCurrent() - blendStart) * animSpeed; float length = entity->GetAnimationLength(sequence, true); if (frame >= (length - 1)) { frame = length - 1; } entity->SetAnimationFrame(frame, blend, sequence, true); break; } case kStateDamage: { if (GetState() != GetPrevState()) SetAnimationSequence(50); float animSpeed = 0.02F; float blend = (Time::GetCurrent() - blendStart) / (blendFinish - blendStart); blend = Math::Min(1.0, blend); frame = (Time::GetCurrent() - blendStart) * animSpeed; float length = entity->GetAnimationLength(sequence, true); if (frame >= (length - 1)) { frame = length - 1; SetState(kStateIdle); } entity->SetAnimationFrame(frame, blend, sequence, true); break; } } entity->UnlockMatrix(); } Quote Link to comment Share on other sites More sharing options...
cassius Posted August 29, 2015 Author Share Posted August 29, 2015 Yeah. That helps thanks. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.