Working on viewing distance for enemies

This commit is contained in:
Vladislav Khorev 2026-07-12 19:09:26 +03:00
parent 33c2b313af
commit 38e45d67b8
6 changed files with 17 additions and 5 deletions

View File

@ -49,7 +49,7 @@
"meshTextures": {
"Ghost": "resources/w/ghost/Ghost_BaseColor.png"
},
"positionX": -0.28594,
"positionX": 0,
"positionY": 0,
"positionZ": 13.9641,
"walkSpeed": 1.5,
@ -60,6 +60,7 @@
"modelCorrectionRotZ": 0.0,
"interactionRadius": 1.0,
"hp": 35,
"visibleRange" : 5.5,
"canAttack": false
},
{
@ -86,6 +87,7 @@
"modelCorrectionRotY": 180.0,
"modelCorrectionRotZ": 0.0,
"hp": 35,
"visibleRange" : 6.5,
"canAttack": true
},
{
@ -112,6 +114,7 @@
"modelCorrectionRotY": 180.0,
"modelCorrectionRotZ": 0.0,
"hp": 35,
"visibleRange" : 6.0,
"canAttack": true
},
{
@ -138,6 +141,7 @@
"modelCorrectionRotY": 180.0,
"modelCorrectionRotZ": 0.0,
"hp": 35,
"visibleRange" : 4.8,
"canAttack": true
},
{

View File

@ -16,8 +16,7 @@ namespace ZL {
extern float x;
extern float y;
const float ATTACK_RANGE = 1.25f;
const float VISIBLE_RANGE = 6.f;
Dialogue::TranslationDatabase Character::nameTranslations;
void Character::loadAnimation(AnimationState animState, const std::string& filename, const std::string& zipFile) {
@ -252,12 +251,12 @@ void Character::update(int64_t deltaMs, const CharacterResolver& resolver) {
if (attackTarget != nullptr) {
float distToGhost = (attackTarget->state.position - state.position).norm();
if (distToGhost >= VISIBLE_RANGE) {
if (distToGhost >= state.visibleRange) {
if (state.isPlayer) {
setTarget(attackTarget->state.position);
}
state.battle_state = 0;
} else if (distToGhost < VISIBLE_RANGE && distToGhost >= ATTACK_RANGE) {
} else if (distToGhost < state.visibleRange && distToGhost >= ATTACK_RANGE) {
setTarget(attackTarget->state.position);
state.battle_state = 0;
} else {

View File

@ -53,6 +53,7 @@ void CharacterState::save(nlohmann::json& out) const
out["pathWaypoints"] = std::move(wpArr);
out["currentWaypointIndex"] = currentWaypointIndex;
out["homeDriftCheckTimer"] = homeDriftCheckTimer;
out["visibleRange"] = visibleRange;
if (!onArrivedCallbackName.empty())
out["onArrivedCallbackName"] = onArrivedCallbackName;
}
@ -69,6 +70,7 @@ void CharacterState::load(const nlohmann::json& in)
facingAngle = in.value("facingAngle", facingAngle);
targetFacingAngle = in.value("targetFacingAngle", targetFacingAngle);
hp = in.value("hp", hp);
visibleRange = in.value("visibleRange", visibleRange);
enabled = in.value("enabled", enabled);
battle_state = in.value("battle_state", battle_state);
currentState = static_cast<AnimationState>(in.value("currentState", static_cast<int>(currentState)));

View File

@ -10,6 +10,8 @@
namespace ZL {
constexpr float VISIBLE_RANGE = 6.f;
enum class AnimationState {
STAND = 0,
WALK = 1,
@ -70,6 +72,8 @@ public:
float hp = 200.f;
float initialHp = 200.f;
float visibleRange = VISIBLE_RANGE;
// --- Combat flags ---
int battle_state = 0;
bool resetAnim = false;

View File

@ -295,6 +295,7 @@ namespace ZL {
data.modelCorrectionRotZ = item.value("modelCorrectionRotZ", 0.0f) * static_cast<float>(M_PI) / 180.0f;
data.facingAngle = item.value("facingAngle", 0.0f) * static_cast<float>(M_PI) / 180.0f;
data.hp = item.value("hp", 100.0f);
data.visibleRange = item.value("visibleRange", VISIBLE_RANGE);
data.canAttack = item.value("canAttack", false);
data.enabled = item.value("enabled", true);
@ -321,6 +322,7 @@ namespace ZL {
st.modelScale = modelScale;
st.setHp(hp);
st.initialHp = hp;
st.visibleRange = visibleRange;
st.canAttack = canAttack;
st.enabled = enabled;
st.interactionRadius = interactionRadius;

View File

@ -74,6 +74,7 @@ namespace ZL {
float modelCorrectionRotZ = 0.0f;
float facingAngle = 0.0f;
float hp = 100.0f;
float visibleRange = VISIBLE_RANGE;
bool canAttack = false;
bool enabled = true;
float interactionRadius = 0.0f;