feat: Implement setFacingPoint script routine

This commit is contained in:
Vsevolod Kremianskii 2020-12-14 23:46:35 +07:00
parent 380943dca6
commit 779ad773d5
6 changed files with 21 additions and 4 deletions

View file

@ -97,9 +97,13 @@ bool SpatialObject::contains(const glm::vec3 &point) const {
}
void SpatialObject::face(const SpatialObject &other) {
if (_id == other._id) return;
if (_id != other._id) {
face(other._position);
}
}
glm::vec2 dir(glm::normalize(other._position - _position));
void SpatialObject::face(const glm::vec3 &point) {
glm::vec2 dir(glm::normalize(point - _position));
_facing = -glm::atan(dir.x, dir.y);
updateTransform();
}

View file

@ -46,6 +46,7 @@ public:
void update(float dt) override;
void face(const SpatialObject &other);
void face(const glm::vec3 &point);
void applyEffect(const std::shared_ptr<Effect> &eff);

View file

@ -176,6 +176,7 @@ private:
script::Variable getTag(const VariablesList &args, script::ExecutionContext &ctx);
script::Variable getWaypointByTag(const VariablesList &args, script::ExecutionContext &ctx);
script::Variable setFacing(const VariablesList &args, script::ExecutionContext &ctx);
script::Variable setFacingPoint(const VariablesList &args, script::ExecutionContext &ctx);
script::Variable setItemStackSize(const VariablesList &args, script::ExecutionContext &ctx);
script::Variable setLocked(const VariablesList &args, script::ExecutionContext &ctx);
script::Variable soundObjectPlay(const VariablesList &args, script::ExecutionContext &ctx);

View file

@ -181,7 +181,7 @@ void Routines::addKotorRoutines() {
add("GetIsDead", Int, { Object }, &Routines::getIsDead);
add("PrintVector", Void, { TVector, Int }, &Routines::printVector);
add("Vector", TVector, { Float, Float, Float }, &Routines::vectorCreate);
add("SetFacingPoint", Void, { TVector });
add("SetFacingPoint", Void, { TVector }, &Routines::setFacingPoint);
add("AngleToVector", TVector, { Float });
add("VectorToAngle", Float, { TVector });
add("TouchAttackMelee", Int, { Object, Int });

View file

@ -342,6 +342,17 @@ Variable Routines::setFacing(const VariablesList &args, ExecutionContext &ctx) {
return Variable();
}
Variable Routines::setFacingPoint(const VariablesList &args, ExecutionContext &ctx) {
auto caller = getCallerAsSpatial(ctx);
if (caller) {
glm::vec3 target(getVector(args, 0));
caller->face(target);
} else {
warn("Routines: setFacingPoint: invalid caller");
}
return Variable();
}
} // namespace game
} // namespace reone

View file

@ -181,7 +181,7 @@ void Routines::addTslRoutines() {
add("GetIsDead", Int, { Object }, &Routines::getIsDead);
add("PrintVector", Void, { TVector, Int }, &Routines::printVector);
add("Vector", TVector, { Float, Float, Float }, &Routines::vectorCreate);
add("SetFacingPoint", Void, { TVector });
add("SetFacingPoint", Void, { TVector }, &Routines::setFacingPoint);
add("AngleToVector", TVector, { Float });
add("VectorToAngle", Float, { TVector });
add("TouchAttackMelee", Int, { Object, Int });