CreateRagdoll.h 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include <Urho3D/Physics/CollisionShape.h>
  5. #include <Urho3D/Physics/Constraint.h>
  6. using namespace Urho3D;
  7. /// Custom component that creates a ragdoll upon collision.
  8. class CreateRagdoll : public Component
  9. {
  10. URHO3D_OBJECT(CreateRagdoll, Component);
  11. public:
  12. /// Construct.
  13. explicit CreateRagdoll(Context* context);
  14. protected:
  15. /// Handle node being assigned.
  16. void OnNodeSet(Node* node) override;
  17. private:
  18. /// Handle scene node's physics collision.
  19. void HandleNodeCollision(StringHash eventType, VariantMap& eventData);
  20. /// Make a bone physical by adding RigidBody and CollisionShape components.
  21. void CreateRagdollBone(const String& boneName, ShapeType type, const Vector3& size, const Vector3& position, const Quaternion& rotation);
  22. /// Join two bones with a Constraint component.
  23. void CreateRagdollConstraint(const String& boneName, const String& parentName, ConstraintType type, const Vector3& axis, const Vector3& parentAxis, const Vector2& highLimit, const Vector2& lowLimit, bool disableCollision = true);
  24. };