improve scripted movement accuracy
This commit is contained in:
@@ -18,6 +18,7 @@ public:
|
||||
int16_t index = -1;
|
||||
Position start = {NULL,NULL,NULL};
|
||||
float velocity;
|
||||
float lastDistance;
|
||||
bool loop = false;
|
||||
|
||||
void load(const std::string& filename) {
|
||||
|
@@ -19,6 +19,15 @@ public:
|
||||
this->position.x += (speed*engine->frameDelta) * a.z;
|
||||
}
|
||||
|
||||
//Returns the position we'd be at *if* we did a movement.
|
||||
Position simulateMove(Angle a, float speed) {
|
||||
Position p;
|
||||
p.z = this->position.z += (speed*engine->frameDelta) * a.x;
|
||||
p.y = this->position.y += (speed*engine->frameDelta) * a.y;
|
||||
p.x = this->position.x += (speed*engine->frameDelta) * a.z;
|
||||
return p;
|
||||
}
|
||||
|
||||
//forward angle
|
||||
Angle fAngle() {
|
||||
Angle a;
|
||||
@@ -66,6 +75,7 @@ public:
|
||||
if (scriptedMove.index == -1 && scriptedMove.start.operator==({0,0,0})) {
|
||||
scriptedMove.index++;
|
||||
}
|
||||
scriptedMove.lastDistance = VectorMath::distance(position,scriptedMove.positions[scriptedMove.index]);
|
||||
|
||||
//We've reached the end of the movement script.
|
||||
if (scriptedMove.index + 1 > scriptedMove.positions.size()) {
|
||||
@@ -76,16 +86,17 @@ public:
|
||||
|
||||
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;
|
||||
//TODO: The angular velocity still isn't qccurate.
|
||||
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) {
|
||||
|
||||
//If the next movement would make us go passed it.
|
||||
if (scriptedMove.lastDistance < VectorMath::distance(simulateMove(a,scriptedMove.velocity),scriptedMove.positions[scriptedMove.index])) {
|
||||
this->position = scriptedMove.positions[scriptedMove.index];
|
||||
//this->angle = scriptedMove.angles[scriptedMove.index];
|
||||
scriptedMove.index++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user