minor fixing, adapting for mobile web
This commit is contained in:
1 parent
44cc0fba67
commit
eac914e073
6 files changed
+393
-129
No files matched your search
+21
-1
@@ -205,7 +205,23 @@ void Character::update(int64_t deltaMs) {
|
||||
cb();
|
||||
}
|
||||
|
||||
targetFacingAngle = facingAngle;
|
||||
// While standing, optionally orient toward another character (e.g. the
|
||||
// player when this NPC is being talked to). The smoothed rotation block
|
||||
// below converges facingAngle to targetFacingAngle.
|
||||
if (faceTarget) {
|
||||
Eigen::Vector3f toFace = faceTarget->position - position;
|
||||
toFace.y() = 0.f;
|
||||
float d = toFace.norm();
|
||||
if (d > 1e-3f) {
|
||||
targetFacingAngle = atan2(toFace.x() / d, -toFace.z() / d);
|
||||
}
|
||||
else {
|
||||
targetFacingAngle = facingAngle;
|
||||
}
|
||||
}
|
||||
else {
|
||||
targetFacingAngle = facingAngle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,6 +283,10 @@ void Character::update(int64_t deltaMs) {
|
||||
float rotStep = rotationSpeed * static_cast<float>(deltaMs) / 1000.f;
|
||||
if (std::fabs(angleDiff) <= rotStep) {
|
||||
facingAngle = targetFacingAngle;
|
||||
// One-shot face-target: once aligned, stop tracking. Otherwise the NPC
|
||||
// would keep snapping to the player every tick after the conversation
|
||||
// started, even as the player moved away.
|
||||
faceTarget = nullptr;
|
||||
} else {
|
||||
facingAngle += (angleDiff > 0.f ? rotStep : -rotStep);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user