Fixing rotation issues in battle mode

This commit is contained in:
Vladislav Khorev committed 2026-04-15 10:34:55 +03:00
1 parent 984d7489d5
commit de2e18e38f
4 files changed
+84 -61

No files matched your search

+77
View File
@@ -67,6 +67,11 @@ void Character::update(int64_t deltaMs) {
}
}
if (battle_state == 1 && attack == 1 && attackTarget != nullptr)
{
targetFacingAngle = atan2(attackTarget->position.x() - position.x(), -(attackTarget->position.z() - position.z()));
}
// Rotate toward target facing angle at constant angular speed
float angleDiff = targetFacingAngle - facingAngle;
while (angleDiff > static_cast<float>(M_PI)) angleDiff -= 2.f * static_cast<float>(M_PI);
@@ -78,6 +83,78 @@ void Character::update(int64_t deltaMs) {
facingAngle += (angleDiff > 0.f ? rotStep : -rotStep);
}
if (canAttack && attackTarget != nullptr)
{
float distToGhost = (attackTarget->position - position).norm();
if (distToGhost >= 10.f)
{
if (isPlayer)
{
setTarget(attackTarget->position);
}
if (battle_state != 0)
{
battle_state = 0;
}
}
else if (distToGhost < 10.0f && distToGhost >= 1.f) {
setTarget(attackTarget->position);
if (battle_state != 0)
{
battle_state = 0;
}
}
else
{
setTarget(position);
if (battle_state != 1)
{
battle_state = 1;
}
}
}
if (attackTarget == nullptr)
{
if (battle_state != 0)
{
battle_state = 0;
attack = 0;
}
}
/*
if (isPlayer) //Player should decide only by himself
{
if (attackTarget != nullptr)
{
auto pos = attackTarget->position;
float distToTarget = (position - pos).norm();
if (distToTarget > 1.0)
{
setTarget(Eigen::Vector3f(pos.x(), 0.f, pos.z()));
}
else
{
if (battle_state != 1)
{
setTarget(position);
battle_state = 1;
//player->attack = 1;
}
}
}
else
{
if (battle_state != 0)
{
battle_state = 0;
attack = 0;
}
}
}*/
if (battle_state == 1)
{
if (currentState == AnimationState::STAND || currentState == AnimationState::WALK) {