Esempio n. 1
0
/*virtual*/ void WBCompEldMesh::Tick(float DeltaTime) {
  XTRACE_FUNCTION;

  UpdateMesh(DeltaTime);

  // Add pseudo root motion. Hack from Couriers.
  if (m_Mesh && m_Mesh->IsAnimated()) {
    Vector AnimationVelocity;
    Angles AnimationRotationalVelocity;
    GetAnimationVelocity(AnimationVelocity, AnimationRotationalVelocity);

    if (AnimationVelocity.LengthSquared() > 0.0f ||
        !AnimationRotationalVelocity.IsZero()) {
      WBCompEldTransform* pTransform =
          GetEntity()->GetTransformComponent<WBCompEldTransform>();
      DEVASSERT(pTransform);

      // Kill velocity in direction of movement.
      if (AnimationVelocity.LengthSquared() > 0.0f) {
        Plane MovementPlane(AnimationVelocity.GetNormalized(), 0.0f);
        pTransform->SetVelocity(
            MovementPlane.ProjectVector(pTransform->GetVelocity()));
      }

      pTransform->ApplyImpulse(AnimationVelocity);
      pTransform->ApplyRotationalImpulse(AnimationRotationalVelocity);
    }
  }
}