Working on battle animation
This commit is contained in:
1 parent
422ff1fbe3
commit
493eb5a5d7
13 files changed
+946723
-25
No files matched your search
+65
-7
@@ -25,8 +25,9 @@ void Character::setTarget(const Eigen::Vector3f& target,
|
||||
}
|
||||
|
||||
AnimationState Character::resolveActiveState() const {
|
||||
|
||||
if (animations.count(currentState)) return currentState;
|
||||
return AnimationState::IDLE;
|
||||
return AnimationState::STAND;
|
||||
}
|
||||
|
||||
void Character::update(int64_t deltaMs) {
|
||||
@@ -46,9 +47,17 @@ void Character::update(int64_t deltaMs) {
|
||||
position += dir * moveAmount;
|
||||
}
|
||||
targetFacingAngle = atan2(dir.x(), -dir.z());
|
||||
currentState = AnimationState::WALK;
|
||||
if (battle_state == 0 && currentState == AnimationState::STAND)
|
||||
{
|
||||
currentState = AnimationState::WALK;
|
||||
}
|
||||
} else {
|
||||
currentState = AnimationState::IDLE;
|
||||
if (battle_state == 0 &&
|
||||
currentState == AnimationState::WALK
|
||||
)
|
||||
{
|
||||
currentState = AnimationState::STAND;
|
||||
}
|
||||
if (onArrivedCallback) {
|
||||
auto cb = std::move(onArrivedCallback);
|
||||
onArrivedCallback = nullptr;
|
||||
@@ -67,17 +76,66 @@ void Character::update(int64_t deltaMs) {
|
||||
facingAngle += (angleDiff > 0.f ? rotStep : -rotStep);
|
||||
}
|
||||
|
||||
// Advance active animation frame
|
||||
AnimationState animState = resolveActiveState();
|
||||
auto it = animations.find(animState);
|
||||
if (battle_state == 1)
|
||||
{
|
||||
if (currentState == AnimationState::STAND || currentState == AnimationState::WALK) {
|
||||
currentState = AnimationState::STAND_TO_ACTION;
|
||||
resetAnim = true;
|
||||
}
|
||||
|
||||
if (attack == 1 && currentState == AnimationState::ACTION_IDLE)
|
||||
{
|
||||
currentState = AnimationState::ACTION_ATTACK;
|
||||
resetAnim = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentState == AnimationState::STAND_TO_ACTION
|
||||
|| currentState == AnimationState::ACTION_IDLE
|
||||
|| currentState == AnimationState::ACTION_ATTACK
|
||||
) {
|
||||
currentState = AnimationState::ACTION_TO_STAND;
|
||||
resetAnim = true;
|
||||
}
|
||||
}
|
||||
|
||||
auto it = animations.find(currentState);
|
||||
if (it == animations.end()) return;
|
||||
|
||||
auto& anim = it->second;
|
||||
|
||||
if (resetAnim)
|
||||
{
|
||||
resetAnim = false;
|
||||
anim.currentFrame = 0;
|
||||
}
|
||||
anim.currentFrame += static_cast<float>(deltaMs) / 24.f;
|
||||
//std::cout << "Current animation frame: " << anim.currentFrame << " / " << anim.totalFrames << " -- " << anim.lastFrame << std::endl;
|
||||
if (static_cast<int>(anim.currentFrame) >= anim.totalFrames-1) {
|
||||
int frms = anim.model.animations[0].keyFrames[anim.model.animations[0].keyFrames.size() - 1].frame;
|
||||
if (static_cast<int>(anim.currentFrame) >= frms) {
|
||||
anim.currentFrame = anim.model.startingFrame;
|
||||
|
||||
if (currentState == AnimationState::STAND_TO_ACTION)
|
||||
{
|
||||
currentState = AnimationState::ACTION_IDLE;
|
||||
resetAnim = true;
|
||||
}
|
||||
if (currentState == AnimationState::ACTION_TO_STAND)
|
||||
{
|
||||
currentState = AnimationState::STAND;
|
||||
resetAnim = true;
|
||||
}
|
||||
|
||||
if (currentState == AnimationState::ACTION_ATTACK)
|
||||
{
|
||||
currentState = AnimationState::ACTION_IDLE;
|
||||
resetAnim = true;
|
||||
attack = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (static_cast<int>(anim.currentFrame) != anim.lastFrame) {
|
||||
anim.model.Interpolate(static_cast<int>(anim.currentFrame));
|
||||
anim.lastFrame = static_cast<int>(anim.currentFrame);
|
||||
|
||||
Reference in new issue
Block a user