diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_ObjectActuator.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_ObjectActuator.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index 931039bc54c..9355ad0adfd 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -81,6 +81,16 @@ KX_ObjectActuator( m_pid = m_torque; } + if (m_bitLocalFlag.CharacterMotion) + { + KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent()); + + if (!parent->GetPhysicsController() || !parent->GetPhysicsController()->IsCharacter()) + { + printf("Character motion enabled on non-character object (%s), falling back to simple motion.\n", parent->GetName().Ptr()); + m_bitLocalFlag.CharacterMotion = false; + } + } if (m_reference) m_reference->RegisterActuator(this); UpdateFuzzyFlags(); @@ -116,10 +126,10 @@ bool KX_ObjectActuator::Update() m_active_combined_velocity = false; } - // Explicitly stop the movement if we're using a character (apply movement is a little different for characters) - if (parent->GetPhysicsController() && parent->GetPhysicsController()->IsCharacter()) { + // Explicitly stop the movement if we're using character motion + if (m_bitLocalFlag.CharacterMotion) { MT_Vector3 vec(0.0, 0.0, 0.0); - parent->ApplyMovement(vec, true); + parent->GetPhysicsController()->SetWalkDirection(vec, true); } m_linear_damping_active = false; @@ -205,8 +215,31 @@ bool KX_ObjectActuator::Update() m_previous_error = e; m_error_accumulator = I; parent->ApplyForce(m_force,(m_bitLocalFlag.LinearVelocity) != 0); - } else + } else if(m_bitLocalFlag.CharacterMotion) { + MT_Vector3 dir = m_dloc; + + if (m_bitLocalFlag.AddOrSetCharLoc) { + MT_Vector3 old_dir = parent->GetPhysicsController()->GetWalkDirection(); + MT_Scalar mag = old_dir.length(); + if (mag < MT_EPSILON) + mag = dir.length(); + dir = (dir + old_dir).normalized() * mag; + } + + // We always want to set the walk direction since a walk direction of (0, 0, 0) should stop the character + parent->GetPhysicsController()->SetWalkDirection(dir, (m_bitLocalFlag.DLoc) != 0); + + if (!m_bitLocalFlag.ZeroDRot) + { + parent->ApplyRotation(m_drot,(m_bitLocalFlag.DRot) != 0); + } + if (m_bitLocalFlag.CharacterJump) + { + parent->GetPhysicsController()->Jump(); + } + } + else { if (!m_bitLocalFlag.ZeroForce) { parent->ApplyForce(m_force,(m_bitLocalFlag.Force) != 0); |