diff options
author | Wuzzy <almikes@aol.com> | 2017-08-11 21:16:09 +0200 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2017-08-13 21:39:08 +0100 |
commit | 2ea26e655d90be538c75aad5cc7ede2c5709179f (patch) | |
tree | 286ad2790a6c97048c85554e5ec9d43f022ddc25 /src | |
parent | 4381fe0a0a0921e6ba79c072045be2dc04be646a (diff) | |
download | minetest-2ea26e655d90be538c75aad5cc7ede2c5709179f.tar.gz minetest-2ea26e655d90be538c75aad5cc7ede2c5709179f.tar.bz2 minetest-2ea26e655d90be538c75aad5cc7ede2c5709179f.zip |
Add slippery group for nodes (players/items slide)
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 2 | ||||
-rw-r--r-- | src/localplayer.cpp | 25 | ||||
-rw-r--r-- | src/localplayer.h | 6 |
3 files changed, 25 insertions, 8 deletions
diff --git a/src/client.cpp b/src/client.cpp index 39bb1e2ff..f7834a02b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -403,7 +403,7 @@ void Client::step(float dtime) // Control local player (0ms) LocalPlayer *player = m_env.getLocalPlayer(); assert(player); - player->applyControl(dtime); + player->applyControl(dtime, &m_env); // Step environment m_env.step(dtime); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index f04be07d6..f72da1b18 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -444,7 +444,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d) move(dtime, env, pos_max_d, NULL); } -void LocalPlayer::applyControl(float dtime) +void LocalPlayer::applyControl(float dtime, ClientEnvironment *env) { // Clear stuff swimming_vertical = false; @@ -660,9 +660,16 @@ void LocalPlayer::applyControl(float dtime) else incH = incV = movement_acceleration_default * BS * dtime; + INodeDefManager *nodemgr = env->getGameDef()->ndef(); + Map *map = &env->getMap(); + bool slippery = false; + const ContentFeatures &f = nodemgr->get(map->getNodeNoEx(getStandingNodePos())); + slippery = itemgroup_get(f.groups, "slippery"); // Accelerate to target speed with maximum increment - accelerateHorizontal(speedH * physics_override_speed, incH * physics_override_speed); - accelerateVertical(speedV * physics_override_speed, incV * physics_override_speed); + accelerateHorizontal(speedH * physics_override_speed, + incH * physics_override_speed, slippery); + accelerateVertical(speedV * physics_override_speed, + incV * physics_override_speed); } v3s16 LocalPlayer::getStandingNodePos() @@ -699,12 +706,20 @@ v3f LocalPlayer::getEyeOffset() const } // Horizontal acceleration (X and Z), Y direction is ignored -void LocalPlayer::accelerateHorizontal(const v3f &target_speed, const f32 max_increase) +void LocalPlayer::accelerateHorizontal(const v3f &target_speed, + const f32 max_increase, bool slippery) { if (max_increase == 0) return; - v3f d_wanted = target_speed - m_speed; + v3f d_wanted = target_speed - m_speed; + if (slippery) { + if (target_speed == v3f(0)) + d_wanted = -m_speed * 0.05f; + else + d_wanted = target_speed * 0.1f - m_speed * 0.1f; + } + d_wanted.Y = 0; f32 dl = d_wanted.getLength(); if (dl > max_increase) diff --git a/src/localplayer.h b/src/localplayer.h index 9f7e92128..67b22b656 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -29,6 +29,7 @@ class Client; class Environment; class GenericCAO; class ClientActiveObject; +class ClientEnvironment; class IGameDef; enum LocalPlayerAnimations @@ -78,7 +79,7 @@ public: void old_move(f32 dtime, Environment *env, f32 pos_max_d, std::vector<CollisionInfo> *collision_info); - void applyControl(float dtime); + void applyControl(float dtime, ClientEnvironment *env); v3s16 getStandingNodePos(); v3s16 getFootstepNodePos(); @@ -143,7 +144,8 @@ public: void setCollisionbox(const aabb3f &box) { m_collisionbox = box; } private: - void accelerateHorizontal(const v3f &target_speed, const f32 max_increase); + void accelerateHorizontal(const v3f &target_speed, + const f32 max_increase, bool slippery); void accelerateVertical(const v3f &target_speed, const f32 max_increase); bool updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max); |