the angle too

This commit is contained in:
2023-12-08 00:50:19 -05:00
parent 4b7d5c4856
commit 1987daf190
3 changed files with 35 additions and 11 deletions

View File

@@ -1,7 +1,13 @@
start 0.01 -2.0 -4.0
start 0.0 0.0 0.0
velocity 2
position 0.1 -2.0 0.0
position 0.01 -2.0 -4.0
position 2.0 -2.0 -4.0
position -2.0 -2.0 -4.0
position 0.01 -2.0 -4.0
loop 1
position 0.0 0.0 -3.2
angle 32.6 0
position -2.4 0 -1.3
angle 30.3 60.6 0
position -0.26 0.11 -2.5
angle 38.6 6.6 0.0
position -0.64 -3.42 -2.37
angle -8.5 14.6 0
position 0.0 0.0 -3.2
angle 32.6 0 0

View File

@@ -18,6 +18,7 @@ public:
int16_t index = -1;
Position start = {NULL,NULL,NULL};
float velocity;
bool loop = false;
void load(const std::string& filename) {
std::ifstream file(filename);
@@ -54,7 +55,15 @@ public:
stream >> x;
velocity = x;
}
else if (prefix == "loop") {
bool x;
stream >> x;
loop = x;
}
}
file.close();
}
void reset() {
index = -1;
}
};

View File

@@ -58,24 +58,33 @@ public:
void doScriptedMovement() {
//If the movement has a set starting position, Then teleport there.
if (scriptedMove.index == -1) {
if (scriptedMove.index == -1 && !scriptedMove.start.operator==({0, 0, 0})) {
this->position = scriptedMove.start;
scriptedMove.index++;
}
scriptedMove.start = position;
//If the movement does not have a starting position
if (scriptedMove.index == -1 && scriptedMove.start.operator==({0,0,0})) {
scriptedMove.index++;
}
//We've reached the end of the movement script.
if (scriptedMove.index + 1 > scriptedMove.positions.size())
return;
if (scriptedMove.index + 1 > scriptedMove.positions.size()) {
if (!scriptedMove.loop)
return;
scriptedMove.reset();
}
Angle a = VectorMath::calcAngle(this->position, scriptedMove.positions[scriptedMove.index]).movementAngle();
move(a,scriptedMove.velocity);
angle.x -= (angle.x - scriptedMove.angles[scriptedMove.index].x)*scriptedMove.velocity*engine->frameDelta;
angle.y -= (angle.y -scriptedMove.angles[scriptedMove.index].y)*scriptedMove.velocity*engine->frameDelta;
angle.z -= (angle.z - scriptedMove.angles[scriptedMove.index].z)*engine->frameDelta;
//TODO: Fix this later, This will break at high speed or if the framerate is low.
//We'll have to detect if the next movement would make us go passed it.
//If it's *super* close just teleport it.
if (VectorMath::distance(this->position,scriptedMove.positions[scriptedMove.index]) <= 0.002) {
this->position = scriptedMove.positions[scriptedMove.index];
//this->angle = scriptedMove.angles[scriptedMove.index];
scriptedMove.index++;
}