Skip to content

Commit eeae2e9

Browse files
bjennings76Brian Dean Jennings
authored andcommitted
feat(InteractableObject): add a rigid body if missing
If no rigid body is found when InteractableObject starts up, it will add one, but make sure the rigid body is set to 'kinematic' so it doesn't start unexpectedly rolling around, popping up, or falling.
1 parent be64a8c commit eeae2e9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_InteractableObject.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@ public void ZeroVelocity()
254254
protected virtual void Awake()
255255
{
256256
rb = this.GetComponent<Rigidbody>();
257+
258+
// If there is no rigid body, add one and set it to 'kinematic'.
259+
if (!rb)
260+
{
261+
rb = gameObject.AddComponent<Rigidbody>();
262+
rb.isKinematic = true;
263+
}
257264
}
258265

259266
protected virtual void Start()

0 commit comments

Comments
 (0)