Modified jumping control to stop "flying" up block-stairs

This commit is contained in:
alexander.pickering 2014-09-20 15:07:39 -04:00
parent 2f170a63c6
commit c571e62658
4 changed files with 65 additions and 48 deletions

View File

@ -29,6 +29,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map.h" #include "map.h"
#include "util/numeric.h" #include "util/numeric.h"
//<dev>
#include <stdio.h>
using namespace std;
//</dev>
/* /*
LocalPlayer LocalPlayer
*/ */
@ -54,7 +61,8 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef):
m_old_node_below_type("air"), m_old_node_below_type("air"),
m_need_to_get_new_sneak_node(true), m_need_to_get_new_sneak_node(true),
m_can_jump(false), m_can_jump(false),
m_cao(NULL) m_cao(NULL),
m_jumptime(0.0)
{ {
// Initialize hp to 0, so that no hearts will be shown if server // Initialize hp to 0, so that no hearts will be shown if server
// doesn't support health points // doesn't support health points
@ -324,6 +332,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
touching_ground = false; touching_ground = false;
MtEvent *e = new SimpleTriggerEvent("PlayerJump"); MtEvent *e = new SimpleTriggerEvent("PlayerJump");
m_gamedef->event()->put(e); m_gamedef->event()->put(e);
cout << "Jumped because " << m_jumptime << " is less than " << env->getTimeOfDay() << "\n";
} }
if(!touching_ground_was && touching_ground){ if(!touching_ground_was && touching_ground){
@ -356,7 +365,12 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
*/ */
const ContentFeatures &f = nodemgr->get(map->getNodeNoEx(getStandingNodePos())); const ContentFeatures &f = nodemgr->get(map->getNodeNoEx(getStandingNodePos()));
// Determine if jumping is possible // Determine if jumping is possible
m_can_jump = touching_ground && !in_liquid; m_can_jump = touching_ground && !in_liquid && (m_jumptime <= env->getTimeOfDay());
if(!touching_ground){
m_jumptime = env->getTimeOfDay()+movement_jump_dealy;
}
//cout << m_jumptime << ":" << (env->getTimeOfDay()) << ":" << m_can_jump << "\n";
if(itemgroup_get(f.groups, "disable_jump")) if(itemgroup_get(f.groups, "disable_jump"))
m_can_jump = false; m_can_jump = false;
} }
@ -478,30 +492,29 @@ void LocalPlayer::applyControl(float dtime)
speedV.Y = -movement_speed_climb; speedV.Y = -movement_speed_climb;
} }
} }
} }
if(continuous_forward)
speedH += move_direction;
if(continuous_forward) if(control.up)
speedH += move_direction; {
if(continuous_forward)
if(control.up) superspeed = true;
{ else
if(continuous_forward) speedH += move_direction;
superspeed = true; }
else if(control.down)
speedH += move_direction; {
} speedH -= move_direction;
if(control.down) }
{ if(control.left)
speedH -= move_direction; {
} speedH += move_direction.crossProduct(v3f(0,1,0));
if(control.left) }
{ if(control.right)
speedH += move_direction.crossProduct(v3f(0,1,0)); {
} speedH += move_direction.crossProduct(v3f(0,-1,0));
if(control.right) }
{
speedH += move_direction.crossProduct(v3f(0,-1,0));
}
if(control.jump) if(control.jump)
{ {
if(free_move) if(free_move)

View File

@ -91,6 +91,7 @@ private:
std::string m_old_node_below_type; std::string m_old_node_below_type;
// Whether recalculation of the sneak node is needed // Whether recalculation of the sneak node is needed
bool m_need_to_get_new_sneak_node; bool m_need_to_get_new_sneak_node;
f32 m_jumptime;
bool m_can_jump; bool m_can_jump;
GenericCAO* m_cao; GenericCAO* m_cao;

View File

@ -53,6 +53,7 @@ Player::Player(IGameDef *gamedef):
m_last_pos(0,0,0), m_last_pos(0,0,0),
m_last_hp(PLAYER_MAX_HP), m_last_hp(PLAYER_MAX_HP),
m_last_inventory(gamedef->idef()) m_last_inventory(gamedef->idef())
m_jumping_dir(0,0,0);
{ {
updateName("<not set>"); updateName("<not set>");
inventory.clear(); inventory.clear();
@ -83,6 +84,7 @@ Player::Player(IGameDef *gamedef):
movement_liquid_fluidity_smooth = 0.5 * BS; movement_liquid_fluidity_smooth = 0.5 * BS;
movement_liquid_sink = 10 * BS; movement_liquid_sink = 10 * BS;
movement_gravity = 9.81 * BS; movement_gravity = 9.81 * BS;
movement_jump_dealy = 0.3 * BS;
// Movement overrides are multipliers and must be 1 by default // Movement overrides are multipliers and must be 1 by default
physics_override_speed = 1; physics_override_speed = 1;

View File

@ -267,6 +267,7 @@ public:
f32 movement_liquid_fluidity_smooth; f32 movement_liquid_fluidity_smooth;
f32 movement_liquid_sink; f32 movement_liquid_sink;
f32 movement_gravity; f32 movement_gravity;
f32 movement_jump_dealy;
float physics_override_speed; float physics_override_speed;
float physics_override_jump; float physics_override_jump;