Skip to content

Commit

Permalink
fix(Locomotion): get correct body physics collider in object control
Browse files Browse the repository at this point in the history
The ObjectControlAction scripts were not always getting the correct
BodyPhysics collider if no BodyPhysics was available as they were
just looking for the child CapsuleCollider and this could exist
in any of the CameraRig children such as on the Controller Objects.

This fix ensures it uses the BodyPhysics script and get the body
collider to use in the ObjectControlAction scripts.
  • Loading branch information
thestonefox committed Jul 11, 2017
1 parent 62aa1e0 commit d4ac472
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum AxisListeners
protected float colliderHeight = 0f;
protected Transform controlledTransform;
protected Transform playArea;
protected VRTK_BodyPhysics internalBodyPhysics;

protected abstract void Process(GameObject controlledGameObject, Transform directionDevice, Vector3 axisDirection, float axis, float deadzone, bool currentlyFalling, bool modifierActive);

Expand All @@ -51,6 +52,7 @@ protected virtual void OnEnable()
break;
}
}
internalBodyPhysics = (internalBodyPhysics == null ? VRTK_SharedMethods.FindEvenInactiveComponent<VRTK_BodyPhysics>() : internalBodyPhysics);
}

protected virtual void OnDisable()
Expand Down Expand Up @@ -110,15 +112,22 @@ protected virtual Vector3 GetObjectCenter(Transform checkObject)

if (checkObject == playArea)
{
CapsuleCollider playAreaCollider = playArea.GetComponentInChildren<CapsuleCollider>();
centerCollider = playAreaCollider;
if (playAreaCollider != null)
bool centerColliderSet = false;

if (internalBodyPhysics != null && internalBodyPhysics.GetBodyColliderContainer() != null)
{
colliderRadius = playAreaCollider.radius;
colliderHeight = playAreaCollider.height;
colliderCenter = playAreaCollider.center;
CapsuleCollider playAreaCollider = internalBodyPhysics.GetBodyColliderContainer().GetComponent<CapsuleCollider>();
centerCollider = playAreaCollider;
if (playAreaCollider != null)
{
centerColliderSet = true;
colliderRadius = playAreaCollider.radius;
colliderHeight = playAreaCollider.height;
colliderCenter = playAreaCollider.center;
}
}
else

if (!centerColliderSet)
{
VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "PlayArea", "CapsuleCollider", "the same or child"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ protected override void Process(GameObject controlledGameObject, Transform direc
Move(controlledGameObject, directionDevice, axisDirection);
}

protected override void OnEnable()
{
internalBodyPhysics = bodyPhysics;
base.OnEnable();
}

protected virtual float CalculateSpeed(float inputValue, bool currentlyFalling, bool modifierActive)
{
float speed = currentSpeed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected override void Process(GameObject controlledGameObject, Transform direc

protected override void OnEnable()
{
internalBodyPhysics = bodyPhysics;
base.OnEnable();
headset = VRTK_DeviceFinder.HeadsetTransform();
}
Expand Down

0 comments on commit d4ac472

Please sign in to comment.