Révision | 4688cf2dd725ade5a3d37c2453d3385d792bb8b8 (tree) |
---|---|
l'heure | 2012-09-23 23:22:54 |
Auteur | angeart <angeart@git....> |
Commiter | angeart |
ジャンプに関する修正
(その場ジャンプに関するバグは一部残っている)
@@ -34,6 +34,7 @@ public: | ||
34 | 34 | prev_rot_(VGet(0, 0, 0)), |
35 | 35 | move_vec_y_(0.0f), |
36 | 36 | jump_flag_(false), |
37 | + jump_end_(false), | |
37 | 38 | flight_duration_ideal_(1.0f), |
38 | 39 | model_height_(1.58f), |
39 | 40 | jump_height_(sqrt(15.0f)*2.0f), |
@@ -160,6 +161,7 @@ public: | ||
160 | 161 | if(current_target_pos != prev_target_pos_ ) |
161 | 162 | { |
162 | 163 | time_now = 0.0f; |
164 | + jump_end_ = false; | |
163 | 165 | } |
164 | 166 | |
165 | 167 |
@@ -191,8 +193,9 @@ public: | ||
191 | 193 | //Logger::Debug("distance_to_target: %d %d", distance_to_target, current_speed_ * timer_->DeltaSec()); |
192 | 194 | |
193 | 195 | // TODO: Y下方向については重力加速度 |
194 | - if (distance_to_target > 2.0){ | |
196 | + if ((distance_to_target > 0.5 || (current_target_pos_ - current_pos_).y > 0 )&& !jump_end_){ | |
195 | 197 | auto direction = current_target_pos_ - current_pos_; |
198 | + if(current_target_vec_y_ != 0)direction.y = 0; | |
196 | 199 | const auto diff_pos = VAdjustLength(direction, current_speed_ * timer_->DeltaSec()); |
197 | 200 | const float roty = atan2(-direction.x, -direction.z); |
198 | 201 | const auto time_entire = VSize(direction) / (current_speed_ * (float)timer_->DeltaSec()); // ターゲットまでの移動完了時間 |
@@ -207,13 +210,12 @@ public: | ||
207 | 210 | 0.5f * -9.8f * (time_entire - time_now) * (time_entire - time_now) * (1.0f / flight_duration_ideal_) * (jump_height_ / 5.0f) * (jump_height_ / 5.0f); // 今からジャンプした際の最終的な位置 |
208 | 211 | */ |
209 | 212 | static auto st_acc = -9.8f; |
210 | - auto acc = -6.5f; | |
213 | + auto acc = -20.0f; | |
211 | 214 | auto prediction_vector = 0.0f; |
212 | 215 | |
213 | - for(acc;acc < -11.0f;acc-=0.1f){ | |
214 | - prediction_vector = jump_height_ * stage_->map_scale() + (acc) * (time_entire - time_now) * (jump_height_ / 5.0f) * (1.0f / flight_duration_ideal_ ); | |
215 | - if( current_target_vec_y_ != 0 && jump_flag_ == false ) | |
216 | - { | |
216 | + if(jump_flag_ == false && current_target_vec_y_ != 0){ | |
217 | + for(acc;acc < -6.5f;acc+=0.1f){ | |
218 | + prediction_vector = jump_height_ * stage_->map_scale() + (acc) * (time_entire - time_now) * (jump_height_ / 5.0f) * (1.0f / flight_duration_ideal_ ); | |
217 | 219 | // ターゲット座標ではジャンプを始めている |
218 | 220 | if( prediction_vector > current_target_vec_y_ - 1 && prediction_vector < current_target_vec_y_ + 1) |
219 | 221 | { |
@@ -236,15 +238,8 @@ public: | ||
236 | 238 | // 床へのめり込みを防止 |
237 | 239 | float floor_y; |
238 | 240 | std::pair<bool, VECTOR> floor_coll; |
239 | - if(!jump_flag_) | |
240 | - { | |
241 | - // 延長線上で接地検査 | |
242 | - floor_coll = stage_->FloorExists(moved_pos,model_height_,8.0f); | |
243 | - }else if(jump_flag_ && current_pos_.y >= moved_pos.y) | |
244 | - { | |
245 | 241 | // 足で接地検査 |
246 | 242 | floor_coll = stage_->FloorExists(moved_pos,model_height_,0); |
247 | - } | |
248 | 243 | //moved_pos.y = std::max(moved_pos.y, floor_y); // 床にあたっているときは床の方がyが高くなる |
249 | 244 | if(!jump_flag_){ |
250 | 245 | // 登ったり下ったりできる段差の大きさの制限を求める |
@@ -268,11 +263,11 @@ public: | ||
268 | 263 | { |
269 | 264 | moved_pos = current_pos_ + VSize(diff_pos) * VNorm(diff); |
270 | 265 | } |
271 | - | |
272 | 266 | } |
273 | - if( floor_coll.first ) | |
267 | + auto floor_exists = stage_->FloorExists(moved_pos, model_height_, 50); | |
268 | + if( floor_exists.first ) | |
274 | 269 | { |
275 | - if( floor_coll.second.y < moved_pos.y ) | |
270 | + if( floor_exists.second.y < moved_pos.y && current_target_pos.y < moved_pos.y) | |
276 | 271 | { |
277 | 272 | jump_flag_ = true; |
278 | 273 | } |
@@ -285,6 +280,12 @@ public: | ||
285 | 280 | { |
286 | 281 | moved_pos = floor_coll.second; |
287 | 282 | move_vec_y_ = 0; |
283 | + jump_flag_ = false; | |
284 | + st_acc = -9.8; | |
285 | + if( moved_pos.x > current_target_pos.x - 1 && moved_pos.x < current_target_pos.x + 1) | |
286 | + { | |
287 | + jump_end_ = true; | |
288 | + } | |
288 | 289 | } |
289 | 290 | }else{ |
290 | 291 | // 上昇している |
@@ -305,7 +306,10 @@ public: | ||
305 | 306 | } |
306 | 307 | |
307 | 308 | data_provider_.set_position(moved_pos); |
308 | - data_provider_.set_theta(current_rot_.y); | |
309 | + if(distance_to_target > 2.0) | |
310 | + { | |
311 | + data_provider_.set_theta(current_rot_.y); | |
312 | + } | |
309 | 313 | |
310 | 314 | MV1SetPosition(model_handle_, moved_pos); |
311 | 315 | MV1SetRotationXYZ(model_handle_, current_rot_); |
@@ -318,7 +322,7 @@ public: | ||
318 | 322 | { |
319 | 323 | current_motion_ = motion.walk_; |
320 | 324 | } |
321 | - }else{ | |
325 | + }else{ | |
322 | 326 | current_motion_ = motion.stand_; |
323 | 327 | } |
324 | 328 |
@@ -372,6 +376,7 @@ private: | ||
372 | 376 | StagePtr stage_; |
373 | 377 | int shadow_handle_; |
374 | 378 | float shadow_size_; |
379 | + bool jump_end_; | |
375 | 380 | |
376 | 381 | struct { |
377 | 382 | int stand_, walk_, run_; |