diff options
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r-- | src/localplayer.cpp | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 77e7a9e16..507f31980 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -42,6 +42,7 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef, const char *name): last_pitch(0), last_yaw(0), last_keyPressed(0), + camera_impact(0.f), last_animation(NO_ANIM), hotbar_image(""), hotbar_selected_image(""), @@ -182,7 +183,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, */ if (control.sneak && m_sneak_node_exists && !(fly_allowed && g_settings->getBool("free_move")) && !in_liquid && - physics_override_sneak) { + physics_override_sneak && !got_teleported) { f32 maxd = 0.5 * BS + sneak_max; v3f lwn_f = intToFloat(m_sneak_node, BS); position.X = rangelim(position.X, lwn_f.X-maxd, lwn_f.X+maxd); @@ -203,18 +204,21 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, } } + if (got_teleported) + got_teleported = false; + // this shouldn't be hardcoded but transmitted from server float player_stepheight = touching_ground ? (BS*0.6) : (BS*0.2); #ifdef __ANDROID__ - player_stepheight += (0.5 * BS); + player_stepheight += (0.6 * BS); #endif v3f accel_f = v3f(0,0,0); collisionMoveResult result = collisionMoveSimple(env, m_gamedef, - pos_max_d, m_collisionbox, player_stepheight, dtime, - position, m_speed, accel_f); + pos_max_d, m_collisionbox, player_stepheight, dtime, + &position, &m_speed, accel_f); /* If the player's feet touch the topside of any node, this is @@ -309,7 +313,8 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, if (sneak_node_found) { f32 cb_max = 0; MapNode n = map->getNodeNoEx(m_sneak_node); - std::vector<aabb3f> nodeboxes = n.getCollisionBoxes(nodemgr); + std::vector<aabb3f> nodeboxes; + n.getCollisionBoxes(nodemgr, &nodeboxes); for (std::vector<aabb3f>::iterator it = nodeboxes.begin(); it != nodeboxes.end(); ++it) { aabb3f box = *it; @@ -344,7 +349,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, } } - if(!touching_ground_was && touching_ground){ + if(!result.standing_on_object && !touching_ground_was && touching_ground) { MtEvent *e = new SimpleTriggerEvent("PlayerRegainGround"); m_gamedef->event()->put(e); @@ -512,15 +517,16 @@ void LocalPlayer::applyControl(float dtime) } } - if(continuous_forward) + if (continuous_forward) speedH += move_direction; - if(control.up) - { - if(continuous_forward) - superspeed = true; - else + if (control.up) { + if (continuous_forward) { + if (fast_move) + superspeed = true; + } else { speedH += move_direction; + } } if(control.down) { @@ -620,3 +626,36 @@ v3s16 LocalPlayer::getStandingNodePos() return floatToInt(getPosition() - v3f(0, BS, 0), BS); } +// Horizontal acceleration (X and Z), Y direction is ignored +void LocalPlayer::accelerateHorizontal(const v3f &target_speed, const f32 max_increase) +{ + if (max_increase == 0) + return; + + v3f d_wanted = target_speed - m_speed; + d_wanted.Y = 0; + f32 dl = d_wanted.getLength(); + if (dl > max_increase) + dl = max_increase; + + v3f d = d_wanted.normalize() * dl; + + m_speed.X += d.X; + m_speed.Z += d.Z; +} + +// Vertical acceleration (Y), X and Z directions are ignored +void LocalPlayer::accelerateVertical(const v3f &target_speed, const f32 max_increase) +{ + if (max_increase == 0) + return; + + f32 d_wanted = target_speed.Y - m_speed.Y; + if (d_wanted > max_increase) + d_wanted = max_increase; + else if (d_wanted < -max_increase) + d_wanted = -max_increase; + + m_speed.Y += d_wanted; +} + |