Jump to content

one shot animation


cassius
 Share

Recommended Posts

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.

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

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();
}

trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...