- {
- m_counter2 -= dtime;
- if(m_counter2 < 0.0)
- {
- m_counter2 += (float)(myrand()%100)/100*3.0;
- //m_yaw += ((float)(myrand()%200)-100)/100*180;
- m_yaw += ((float)(myrand()%200)-100)/100*90;
- m_yaw = wrapDegrees(m_yaw);
- }
- }
- }
-
- if((m_speed_f - target_speed).getLength() > BS*4 || player_is_too_close)
- accelerate_xz(m_speed_f, target_speed, dtime*BS*8);
- else
- accelerate_xz(m_speed_f, target_speed, dtime*BS*4);
-
- m_oldpos = m_base_position;
-
- /*
- Move it, with collision detection
- */
-
- core::aabbox3d<f32> box(-BS/3.,0.0,-BS/3., BS/3.,BS*5./3.,BS/3.);
- collisionMoveResult moveresult;
- // Maximum movement without glitches
- f32 pos_max_d = BS*0.25;
- /*// Limit speed
- if(m_speed_f.getLength()*dtime > pos_max_d)
- m_speed_f *= pos_max_d / (m_speed_f.getLength()*dtime);*/
- v3f pos_f = getBasePosition();
- v3f pos_f_old = pos_f;
- moveresult = collisionMovePrecise(&m_env->getMap(), pos_max_d,
- box, dtime, pos_f, m_speed_f);
- m_touching_ground = moveresult.touching_ground;
-
- // Do collision damage
- float tolerance = BS*12;
- float factor = BS*0.5;
- v3f speed_diff = old_speed - m_speed_f;
- // Increase effect in X and Z
- speed_diff.X *= 2;
- speed_diff.Z *= 2;
- float vel = speed_diff.getLength();
- if(vel > tolerance)
- {
- f32 damage_f = (vel - tolerance)/BS*factor;
- u16 damage = (u16)(damage_f+0.5);
- doDamage(damage);
- }