LocalPlayer::LocalPlayer(IGameDef *gamedef):
Player(gamedef),
+ isAttached(false),
+ overridePosition(v3f(0,0,0)),
+ last_position(v3f(0,0,0)),
+ last_speed(v3f(0,0,0)),
+ last_pitch(0),
+ last_yaw(0),
+ last_keyPressed(0),
m_sneak_node(32767,32767,32767),
m_sneak_node_exists(false),
m_old_node_below(32767,32767,32767),
v3f old_speed = m_speed;
- // Skip collision detection if a special movement mode is used
+ // Copy parent position if local player is attached
+ if(isAttached)
+ {
+ setPosition(overridePosition);
+ return;
+ }
+
+ // Skip collision detection if noclip mode is used
bool fly_allowed = m_gamedef->checkLocalPrivilege("fly");
- bool free_move = fly_allowed && g_settings->getBool("free_move");
+ bool noclip = m_gamedef->checkLocalPrivilege("noclip") &&
+ g_settings->getBool("noclip");
+ bool free_move = noclip && fly_allowed && g_settings->getBool("free_move");
if(free_move)
{
position += m_speed * dtime;
If sneaking, keep in range from the last walked node and don't
fall off from it
*/
- if(control.sneak && m_sneak_node_exists)
+ if(control.sneak && m_sneak_node_exists && !g_settings->getBool("free_move"))
{
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);
position.Z = rangelim(position.Z, lwn_f.Z-maxd, lwn_f.Z+maxd);
- f32 min_y = lwn_f.Y + 0.5*BS;
- if(position.Y < min_y)
+ if(!is_climbing)
{
- position.Y = min_y;
+ f32 min_y = lwn_f.Y + 0.5*BS;
+ if(position.Y < min_y)
+ {
+ position.Y = min_y;
- if(m_speed.Y < 0)
- m_speed.Y = 0;
+ if(m_speed.Y < 0)
+ m_speed.Y = 0;
+ }
}
}
bool touching_ground_was = touching_ground;
touching_ground = result.touching_ground;
- bool standing_on_unloaded = result.standing_on_unloaded;
+ //bool standing_on_unloaded = result.standing_on_unloaded;
/*
Check the nodes under the player to see from which node the
/*
Report collisions
*/
- if(collision_info)
+ bool bouncy_jump = false;
+ // Dont report if flying
+ if(collision_info && !(g_settings->getBool("free_move") && fly_allowed))
{
- // Report fall collision
- if(old_speed.Y < m_speed.Y - 0.1 && !standing_on_unloaded)
- {
- CollisionInfo info;
- info.t = COLLISION_FALL;
- info.speed = m_speed.Y - old_speed.Y;
+ for(size_t i=0; i<result.collisions.size(); i++){
+ const CollisionInfo &info = result.collisions[i];
collision_info->push_back(info);
+ if(info.new_speed.Y - info.old_speed.Y > 0.1*BS &&
+ info.bouncy)
+ bouncy_jump = true;
}
}
+ if(bouncy_jump && control.jump){
+ m_speed.Y += 6.5*BS;
+ touching_ground = false;
+ MtEvent *e = new SimpleTriggerEvent("PlayerJump");
+ m_gamedef->event()->put(e);
+ }
+
if(!touching_ground_was && touching_ground){
MtEvent *e = new SimpleTriggerEvent("PlayerRegainGround");
m_gamedef->event()->put(e);
v3s16 camera_np = floatToInt(getEyePosition(), BS);
MapNode n = map.getNodeNoEx(camera_np);
if(n.getContent() != CONTENT_IGNORE){
- if(nodemgr->get(n).walkable){
+ if(nodemgr->get(n).walkable && nodemgr->get(n).solidness == 2){
camera_barely_in_ceiling = true;
}
}
setPitch(control.pitch);
setYaw(control.yaw);
-
+
+ // Nullify speed and don't run positioning code if the player is attached
+ if(isAttached)
+ {
+ setSpeed(v3f(0,0,0));
+ return;
+ }
+
v3f move_direction = v3f(0,0,1);
move_direction.rotateXZBy(getYaw());
// Whether superspeed mode is used or not
bool superspeed = false;
- // If free movement and fast movement, always move fast
- if(free_move && fast_move)
- superspeed = true;
-
// Old descend control
if(g_settings->getBool("aux1_descends"))
{
+ // If free movement and fast movement, always move fast
+ if(free_move && fast_move)
+ superspeed = true;
+
// Auxiliary button 1 (E)
if(control.aux1)
{
// Auxiliary button 1 (E)
if(control.aux1)
{
- if(!free_move && !is_climbing)
+ if(!is_climbing)
{
- // If not free movement but fast is allowed, aux1 is
- // "Turbo button"
+ // aux1 is "Turbo button"
if(fast_move)
superspeed = true;
}
{
// In free movement mode, sneak descends
v3f speed = getSpeed();
- if(fast_move)
+ if(fast_move && control.aux1)
speed.Y = -20*BS;
else
speed.Y = -walkspeed_max;
if(free_move)
{
v3f speed = getSpeed();
- if(fast_move)
- speed.Y = 20*BS;
- else
- speed.Y = walkspeed_max;
+
+ if(g_settings->getBool("aux1_descends"))
+ {
+ if(fast_move)
+ speed.Y = 20*BS;
+ else
+ speed.Y = walkspeed_max;
+ } else {
+ if(fast_move && control.aux1)
+ speed.Y = 20*BS;
+ else
+ speed.Y = walkspeed_max;
+ }
+
setSpeed(speed);
}
else if(m_can_jump)
// The speed of the player (Y is ignored)
if(superspeed)
speed = speed.normalize() * walkspeed_max * 5.0;
- else if(control.sneak)
+ else if(control.sneak && !free_move)
speed = speed.normalize() * walkspeed_max / 3.0;
else
speed = speed.normalize() * walkspeed_max;
f32 inc = walk_acceleration * BS * dtime;
// Faster acceleration if fast and free movement
- if(free_move && fast_move)
+ if(free_move && fast_move && superspeed)
inc = walk_acceleration * BS * dtime * 10;
// Accelerate to target speed with maximum increment