diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index bf81a071d..11a2b972d 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -95,6 +95,24 @@ void InputManager::handleStaticAction(int key, int value) case KEY_LCONTROL: control_is_pressed = value!=0; break; + case KEY_KEY_J: + { + Kart* kart = world->getLocalPlayerKart(0); + kart->fly(); + break; + } + case KEY_KEY_I: + { + Kart* kart = world->getLocalPlayerKart(0); + kart->flyUp(); + break; + } + case KEY_KEY_K: + { + Kart* kart = world->getLocalPlayerKart(0); + kart->flyDown(); + break; + } case KEY_F1: if (world && race_manager->getNumPlayers() ==1 ) { diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 7ce169752..c2b35ad9a 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -96,7 +96,8 @@ Kart::Kart (const std::string& ident, int position, m_camera = NULL; m_controller = NULL; m_saved_controller = NULL; - + m_flying = false; + m_view_blocked_by_plunger = 0; // Initialize custom sound vector (TODO: add back when properly done) @@ -267,6 +268,13 @@ void Kart::createPhysics() } // createPhysics +void Kart::fly() +{ + m_flying = true; + Moveable::fly(); + //m_vehicle->m_flying = true; +} + // ---------------------------------------------------------------------------- /** Starts the engine sound effect. Called once the track intro phase is over. */ @@ -663,14 +671,17 @@ void Kart::update(float dt) m_controls.m_fire = false; } - // When really on air, free fly, when near ground, try to glide / adjust for landing - // If zipped, be stable, so ramp+zipper can allow nice jumps without scripting the fly - if(!isNearGround() && - MaxSpeed::getSpeedIncreaseTimeLeft(MS_INCREASE_ZIPPER)<=0.0f ) - m_uprightConstraint->setLimit(M_PI); - else - m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance()); - + if (!m_flying) + { + // When really on air, free fly, when near ground, try to glide / adjust for landing + // If zipped, be stable, so ramp+zipper can allow nice jumps without scripting the fly + if(!isNearGround() && + MaxSpeed::getSpeedIncreaseTimeLeft(MS_INCREASE_ZIPPER)<=0.0f ) + m_uprightConstraint->setLimit(M_PI); + else + m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance()); + } + // TODO: hiker said this probably will be moved to btKart or so when updating bullet engine. // Neutralize any yaw change if the kart leaves the ground, so the kart falls more or less // straight after jumping, but still allowing some "boat shake" (roll and pitch). @@ -1162,8 +1173,28 @@ void Kart::updatePhysics(float dt) + handleSlipstream(dt); if(m_attachment->getType()==ATTACH_PARACHUTE) engine_power*=0.2f; + if (m_flying) + { + if (m_controls.m_accel) + { + float orientation = getHeading(); + m_body->applyCentralImpulse(btVector3(60.0f*sin(orientation), 0.0, 60.0f*cos(orientation))); + } + if (m_controls.m_steer != 0.0f) + { + m_body->applyTorque(btVector3(0.0, m_controls.m_steer * 2000.0f, 0.0)); + } + if (m_controls.m_brake) + { + float orientation = getHeading(); + m_body->applyCentralImpulse(btVector3(-60.0f*sin(orientation), 0.0, -60.0f*cos(orientation))); + } + } + + if(m_controls.m_accel) // accelerating - { // For a short time after a collision disable the engine, + { + // For a short time after a collision disable the engine, // so that the karts can bounce back a bit from the obstacle. if(m_bounce_back_time>0.0f) engine_power = 0.0f; diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index fc8076d3c..9bbf53527 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -64,6 +64,9 @@ class Kart : public TerrainInfo, public Moveable, public EmergencyAnimation, public MaxSpeed { private: + + bool m_flying; + /** Reset position. */ btTransform m_reset_transform; /** Index of kart in world. */ @@ -226,6 +229,8 @@ public: float getActualWheelForce(); bool isSlipstreamReady() const; + virtual void fly(); + void resetBrakes (); void startEngineSFX (); void adjustSpeed (float f); diff --git a/src/karts/moveable.cpp b/src/karts/moveable.cpp index c1d7523ed..67f923d96 100644 --- a/src/karts/moveable.cpp +++ b/src/karts/moveable.cpp @@ -90,6 +90,26 @@ void Moveable::reset() } // reset +//----------------------------------------------------------------------------- + +void Moveable::fly() +{ + m_body->setGravity(btVector3(0.0, 8.0, 0.0)); + //m_body->setMassProps( 0.0, btVector3(0.0, 0.0, 0.0) ); + flyUp(); + //m_body->applyCentralForce( btVector3(0.0, 9000.0, 0.0) ); +} + +void Moveable::flyUp() +{ + m_body->applyCentralImpulse(btVector3(0.0, 100.0, 0.0)); +} + +void Moveable::flyDown() +{ + m_body->applyCentralImpulse(btVector3(0.0, -100.0, 0.0)); +} + //----------------------------------------------------------------------------- /** Updates the current position and rotation from the corresponding physics * body, and then calls updateGraphics to position the model correctly. diff --git a/src/karts/moveable.hpp b/src/karts/moveable.hpp index 2a528ecb7..902983b59 100644 --- a/src/karts/moveable.hpp +++ b/src/karts/moveable.hpp @@ -85,6 +85,11 @@ public: const btQuaternion getRotation() const {return m_transform.getRotation(); } + /** Enter flying mode */ + virtual void fly(); + virtual void flyUp(); + virtual void flyDown(); + /** Sets the XYZ coordinates of the moveable. */ void setXYZ(const Vec3& a) {