Skip to content

Commit

Permalink
fix(Pointer): correctly plot play area cursor based on offset
Browse files Browse the repository at this point in the history
Previously, the play area cursor would be plotted based on the headset
location within the play area, but this is not the correct behaviour if
the Teleporter script has the `Headset Position Compensation` parameter
unchecked as the headset position should not be taken into
consideration, otherwise the `[CameraRig]` is teleported to the wrong
destination out by the margin of the headset offset.

This fix ensure the teleport option is honoured in the pointer.
  • Loading branch information
thestonefox committed Jul 7, 2016
1 parent a21a80d commit dcb8156
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Expand Up @@ -44,6 +44,7 @@ public abstract class VRTK_DestinationMarker : MonoBehaviour

protected string invalidTargetWithTagOrClass;
protected bool checkNavMesh;
protected bool headsetPositionCompensation;

public virtual void OnDestinationMarkerEnter(DestinationMarkerEventArgs e)
{
Expand Down Expand Up @@ -73,6 +74,11 @@ public virtual void SetNavMeshCheck(bool state)
checkNavMesh = state;
}

public virtual void SetHeadsetPositionCompensation(bool state)
{
headsetPositionCompensation = state;
}

protected DestinationMarkerEventArgs SeDestinationMarkerEvent(float distance, Transform target, Vector3 position, uint controllerIndex)
{
DestinationMarkerEventArgs e;
Expand Down
Expand Up @@ -127,9 +127,13 @@ protected virtual void InitPointer()

protected virtual void SetPlayAreaCursorTransform(Vector3 destination)
{
var playAreaPos = new Vector3(playArea.transform.position.x, 0, playArea.transform.position.z);
var headsetPos = new Vector3(headset.position.x, 0, headset.position.z);
var offset = playAreaPos - headsetPos;
var offset = Vector3.zero;
if(headsetPositionCompensation)
{
var playAreaPos = new Vector3(playArea.transform.position.x, 0, playArea.transform.position.z);
var headsetPos = new Vector3(headset.position.x, 0, headset.position.z);
offset = playAreaPos - headsetPos;
}
playAreaCursor.transform.position = destination + offset;
}

Expand Down
1 change: 1 addition & 0 deletions Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_BasicTeleport.cs
Expand Up @@ -46,6 +46,7 @@ public void InitDestinationSetListener(GameObject markerMaker)
worldMarker.DestinationMarkerSet += new DestinationMarkerEventHandler(DoTeleport);
worldMarker.SetInvalidTarget(ignoreTargetWithTagOrClass);
worldMarker.SetNavMeshCheck(limitToNavMesh);
worldMarker.SetHeadsetPositionCompensation(headsetPositionCompensation);
}
}
}
Expand Down

0 comments on commit dcb8156

Please sign in to comment.