diff --git a/Source/Engine/Physics/Joints/Joint.cpp b/Source/Engine/Physics/Joints/Joint.cpp
index f9808efc6..79ef9d4d5 100644
--- a/Source/Engine/Physics/Joints/Joint.cpp
+++ b/Source/Engine/Physics/Joints/Joint.cpp
@@ -101,6 +101,28 @@ void Joint::SetJointLocation(const Vector3& location)
}
}
+FORCE_INLINE Quaternion WorldToLocal(const Quaternion& world, const Quaternion& orientation)
+{
+ Quaternion rot;
+ const Quaternion invRotation = world.Conjugated();
+ Quaternion::Multiply(invRotation, orientation, rot);
+ rot.Normalize();
+ return rot;
+}
+
+void Joint::SetJointOrientation(const Quaternion& orientation)
+{
+ if (GetParent())
+ {
+ SetLocalOrientation(WorldToLocal(GetParent()->GetOrientation(), orientation));
+ }
+ if (Target)
+ {
+ //SetTargetAnchor(Target->GetTransform().WorldToLocal(orientation));
+ SetTargetAnchorRotation(WorldToLocal(Target->GetOrientation(), orientation));
+ }
+}
+
void Joint::GetCurrentForce(Vector3& linear, Vector3& angular) const
{
if (_joint && _joint->getConstraint())
diff --git a/Source/Engine/Physics/Joints/Joint.h b/Source/Engine/Physics/Joints/Joint.h
index 95d33c421..046570462 100644
--- a/Source/Engine/Physics/Joints/Joint.h
+++ b/Source/Engine/Physics/Joints/Joint.h
@@ -135,6 +135,13 @@ public:
/// The joint location to set (world-space).
API_FUNCTION() void SetJointLocation(const Vector3& location);
+ ///
+ /// Sets the orientation of the joint by automatically computing local orientation and target anchor orientation to orient a joint at the given rotation (world-space).
+ ///
+ /// Use this utility to automatically rotate joint at the given location after setting up joint parent and target.
+ /// The joint orientation to set (world-space).
+ API_FUNCTION() void SetJointOrientation(const Quaternion& orientation);
+
///
/// Gets the current force applied by the solver to maintain all constraints.
///