diff options
author | sfan5 <sfan5@live.de> | 2019-07-16 14:00:42 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2019-08-10 19:44:27 +0200 |
commit | cf64054390970f3cf974afb2b174340a3e1da382 (patch) | |
tree | 9f3a62d3f935ae76f00fb1c0002f9ba59e59f219 /src/client | |
parent | b19400aa74f30ef61ba0c1bb4a25a978e7cf4125 (diff) | |
download | minetest-cf64054390970f3cf974afb2b174340a3e1da382.tar.gz minetest-cf64054390970f3cf974afb2b174340a3e1da382.tar.bz2 minetest-cf64054390970f3cf974afb2b174340a3e1da382.zip |
Implement adding velocity to player from Lua
The intended usecase is knockback, but there's potential for more.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/client.h | 1 | ||||
-rw-r--r-- | src/client/localplayer.cpp | 10 | ||||
-rw-r--r-- | src/client/localplayer.h | 6 |
3 files changed, 17 insertions, 0 deletions
diff --git a/src/client/client.h b/src/client/client.h index 15a4689c1..3bfb1631e 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -227,6 +227,7 @@ public: void handleCommand_SrpBytesSandB(NetworkPacket *pkt); void handleCommand_FormspecPrepend(NetworkPacket *pkt); void handleCommand_CSMRestrictionFlags(NetworkPacket *pkt); + void handleCommand_PlayerSpeed(NetworkPacket *pkt); void ProcessData(NetworkPacket *pkt); diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 0e273a16a..c356f7c24 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -188,6 +188,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, // Copy parent position if local player is attached if (isAttached) { setPosition(overridePosition); + added_velocity = v3f(); // ignored return; } @@ -201,9 +202,13 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, if (noclip && free_move) { position += m_speed * dtime; setPosition(position); + added_velocity = v3f(); // ignored return; } + m_speed += added_velocity; + added_velocity = v3f(); + /* Collision detection */ @@ -782,6 +787,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, if (isAttached) { setPosition(overridePosition); m_sneak_node_exists = false; + added_velocity = v3f(); return; } @@ -795,9 +801,13 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, position += m_speed * dtime; setPosition(position); m_sneak_node_exists = false; + added_velocity = v3f(); return; } + m_speed += added_velocity; + added_velocity = v3f(); + /* Collision detection */ diff --git a/src/client/localplayer.h b/src/client/localplayer.h index 84cfa583a..16e7996ae 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -149,6 +149,11 @@ public: bool getAutojump() const { return m_autojump; } + inline void addVelocity(const v3f &vel) + { + added_velocity += vel; + } + private: void accelerate(const v3f &target_speed, const f32 max_increase_H, const f32 max_increase_V, const bool use_pitch); @@ -194,6 +199,7 @@ private: float m_zoom_fov = 0.0f; bool m_autojump = false; float m_autojump_time = 0.0f; + v3f added_velocity = v3f(0.0f, 0.0f, 0.0f); // cleared on each move() GenericCAO *m_cao = nullptr; Client *m_client; |