summary refs log tree commit diff stats
path: root/src/systems/pondering.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems/pondering.cpp')
-rw-r--r--src/systems/pondering.cpp47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index d841679..649a03a 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp
@@ -44,6 +44,7 @@ void PonderingSystem::initializeBody(
44 44
45 if (type == PonderableComponent::Type::freefalling) 45 if (type == PonderableComponent::Type::freefalling)
46 { 46 {
47 ponderable.targetVel.y() = TERMINAL_VELOCITY;
47 ponderable.accel.y() = NORMAL_GRAVITY; 48 ponderable.accel.y() = NORMAL_GRAVITY;
48 } 49 }
49} 50}
@@ -57,6 +58,8 @@ void PonderingSystem::initPrototype(id_type prototype)
57 ponderable.vel.y() = 0.0; 58 ponderable.vel.y() = 0.0;
58 ponderable.accel.x() = 0.0; 59 ponderable.accel.x() = 0.0;
59 ponderable.accel.y() = 0.0; 60 ponderable.accel.y() = 0.0;
61 ponderable.targetVel.x() = 0.0;
62 ponderable.targetVel.y() = 0.0;
60 ponderable.grounded = false; 63 ponderable.grounded = false;
61 ponderable.frozen = false; 64 ponderable.frozen = false;
62 ponderable.collidable = true; 65 ponderable.collidable = true;
@@ -98,12 +101,48 @@ void PonderingSystem::tickBody(
98 // Accelerate 101 // Accelerate
99 if (!ponderable.frozen) 102 if (!ponderable.frozen)
100 { 103 {
101 ponderable.vel += ponderable.accel * dt; 104 // Determine the effective acceleration, which should be in the direction of
105 // the target velocity.
106 vec2d effAcc = ponderable.accel;
102 107
103 if ((ponderable.type == PonderableComponent::Type::freefalling) 108 if (ponderable.vel.x() == ponderable.targetVel.x())
104 && (ponderable.vel.y() > TERMINAL_VELOCITY))
105 { 109 {
106 ponderable.vel.y() = TERMINAL_VELOCITY; 110 effAcc.x() = 0.0;
111 }
112 else if ((ponderable.accel.x() > 0 &&
113 ponderable.targetVel.x() < ponderable.vel.x()) ||
114 (ponderable.accel.x() < 0 &&
115 ponderable.targetVel.x() > ponderable.vel.x()))
116 {
117 effAcc.x() = -effAcc.x();
118 }
119
120 if (ponderable.vel.y() == ponderable.targetVel.y())
121 {
122 effAcc.y() = 0.0;
123 }
124 else if ((ponderable.accel.y() > 0 &&
125 ponderable.targetVel.y() < ponderable.vel.y()) ||
126 (ponderable.accel.y() < 0 &&
127 ponderable.targetVel.y() > ponderable.vel.y()))
128 {
129 effAcc.y() = -effAcc.y();
130 }
131
132 // Accelerate
133 ponderable.vel += effAcc * dt;
134
135 // If the velocity crossed the target velocity, set it to the target
136 if ((effAcc.x() > 0 && ponderable.vel.x() > ponderable.targetVel.x()) ||
137 (effAcc.x() < 0 && ponderable.vel.x() < ponderable.targetVel.x()))
138 {
139 ponderable.vel.x() = ponderable.targetVel.x();
140 }
141
142 if ((effAcc.y() > 0 && ponderable.vel.y() > ponderable.targetVel.y()) ||
143 (effAcc.y() < 0 && ponderable.vel.y() < ponderable.targetVel.y()))
144 {
145 ponderable.vel.y() = ponderable.targetVel.y();
107 } 146 }
108 } 147 }
109 148