Only face target when in combat, not when selecting friendly NPCs

This commit is contained in:
Kelsi 2026-02-07 13:56:58 -08:00
parent ef15079613
commit 6d8732e5cc
3 changed files with 5 additions and 3 deletions

View file

@ -120,6 +120,7 @@ public:
// Targeting support // Targeting support
void setTargetPosition(const glm::vec3* pos); void setTargetPosition(const glm::vec3* pos);
void setInCombat(bool combat) { inCombat_ = combat; }
bool isMoving() const; bool isMoving() const;
void triggerMeleeSwing(); void triggerMeleeSwing();
void setEquippedWeaponType(uint32_t inventoryType) { equippedWeaponInvType_ = inventoryType; meleeAnimId = 0; } void setEquippedWeaponType(uint32_t inventoryType) { equippedWeaponInvType_ = inventoryType; meleeAnimId = 0; }
@ -228,6 +229,7 @@ private:
// Target facing // Target facing
const glm::vec3* targetPosition = nullptr; const glm::vec3* targetPosition = nullptr;
bool inCombat_ = false;
// Selection circle rendering // Selection circle rendering
uint32_t selCircleVAO = 0; uint32_t selCircleVAO = 0;

View file

@ -872,12 +872,11 @@ void Renderer::update(float deltaTime) {
// Movement-facing comes from camera controller and is decoupled from LMB orbit. // Movement-facing comes from camera controller and is decoupled from LMB orbit.
if (cameraController->isMoving() || cameraController->isRightMouseHeld()) { if (cameraController->isMoving() || cameraController->isRightMouseHeld()) {
characterYaw = cameraController->getFacingYaw(); characterYaw = cameraController->getFacingYaw();
} else if (targetPosition && !emoteActive && !cameraController->isMoving()) { } else if (inCombat_ && targetPosition && !emoteActive) {
// Face target when idle // Face target when in combat and idle
glm::vec3 toTarget = *targetPosition - characterPosition; glm::vec3 toTarget = *targetPosition - characterPosition;
if (glm::length(glm::vec2(toTarget.x, toTarget.y)) > 0.1f) { if (glm::length(glm::vec2(toTarget.x, toTarget.y)) > 0.1f) {
float targetYaw = glm::degrees(std::atan2(toTarget.y, toTarget.x)); float targetYaw = glm::degrees(std::atan2(toTarget.y, toTarget.x));
// Smooth rotation toward target
float diff = targetYaw - characterYaw; float diff = targetYaw - characterYaw;
while (diff > 180.0f) diff -= 360.0f; while (diff > 180.0f) diff -= 360.0f;
while (diff < -180.0f) diff += 360.0f; while (diff < -180.0f) diff += 360.0f;

View file

@ -167,6 +167,7 @@ void GameScreen::render(game::GameHandler& gameHandler) {
// Update renderer face-target position and selection circle // Update renderer face-target position and selection circle
auto* renderer = core::Application::getInstance().getRenderer(); auto* renderer = core::Application::getInstance().getRenderer();
if (renderer) { if (renderer) {
renderer->setInCombat(gameHandler.isAutoAttacking());
static glm::vec3 targetGLPos; static glm::vec3 targetGLPos;
if (gameHandler.hasTarget()) { if (gameHandler.hasTarget()) {
auto target = gameHandler.getTarget(); auto target = gameHandler.getTarget();