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 "util/numeric.h"
//<dev>
#include <stdio.h>
using namespace std;
//</dev>
/*
LocalPlayer
*/
@ -54,7 +61,8 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef):
m_old_node_below_type("air"),
m_need_to_get_new_sneak_node(true),
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
// doesn't support health points
@ -324,6 +332,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
touching_ground = false;
MtEvent *e = new SimpleTriggerEvent("PlayerJump");
m_gamedef->event()->put(e);
cout << "Jumped because " << m_jumptime << " is less than " << env->getTimeOfDay() << "\n";
}
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()));
// 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"))
m_can_jump = false;
}
@ -479,7 +493,6 @@ void LocalPlayer::applyControl(float dtime)
}
}
}
if(continuous_forward)
speedH += move_direction;

View File

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

View File

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

View File

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