Skip to content

Commit

Permalink
feat(Locomotion): add method to force teleport.
Browse files Browse the repository at this point in the history
The Basic Teleport script (and therefore any child script) now has a
method called `ForceTeleport` which can be used to force the teleporter
to update it's position without needing to listen to a destination
marker event. Which can be useful if the play area needs setting to
a specific position without wanting to use a destination marker, such
as setting a spawn point.
  • Loading branch information
thestonefox committed May 8, 2017
1 parent 9a98d09 commit 2065a7f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
33 changes: 31 additions & 2 deletions Assets/VRTK/Scripts/Locomotion/VRTK_BasicTeleport.cs
Expand Up @@ -114,7 +114,7 @@ public virtual bool ValidLocation(Transform target, Vector3 destinationPosition)
}

bool validNavMeshLocation = false;
if (target)
if (target != null)
{
NavMeshHit hit;
validNavMeshLocation = NavMesh.SamplePosition(destinationPosition, out hit, navMeshLimitDistance, NavMesh.AllAreas);
Expand All @@ -124,7 +124,36 @@ public virtual bool ValidLocation(Transform target, Vector3 destinationPosition)
validNavMeshLocation = true;
}

return (validNavMeshLocation && target && !(VRTK_PolicyList.Check(target.gameObject, targetListPolicy)));
return (validNavMeshLocation && target != null && !(VRTK_PolicyList.Check(target.gameObject, targetListPolicy)));
}

/// <summary>
/// The ForceTeleport/1 method forces the teleport to update position without needing to listen for a Destination Marker event.
/// </summary>
/// <param name="teleportArgs">The pseudo Destination Marker event for the teleport action.</param>
public virtual void ForceTeleport(DestinationMarkerEventArgs teleportArgs)
{
DoTeleport(this, teleportArgs);
}

/// <summary>
/// The ForceTeleport/3 method forces the teleport to update position without needing to listen for a Destination Marker event.
/// It will build a destination marker out of the provided parameters.
/// </summary>
/// <param name="target">The Transform of the destination object.</param>
/// <param name="destinationPosition">The world position to teleport to.</param>
/// <param name="destinationRotation">The world rotation to teleport to.</param>
public virtual void ForceTeleport(Transform target, Vector3 destinationPosition, Quaternion? destinationRotation = null)
{
DestinationMarkerEventArgs teleportArgs = new DestinationMarkerEventArgs();
teleportArgs.distance = Vector3.Distance(new Vector3(headset.position.x, playArea.position.y, headset.position.z), destinationPosition);
teleportArgs.target = target;
teleportArgs.raycastHit = new RaycastHit();
teleportArgs.destinationPosition = destinationPosition;
teleportArgs.destinationRotation = destinationRotation;
teleportArgs.forceDestinationPosition = false;
teleportArgs.enableTeleport = true;
ForceTeleport(teleportArgs);
}

protected virtual void OnEnable()
Expand Down
24 changes: 24 additions & 0 deletions DOCUMENTATION.md
Expand Up @@ -1659,6 +1659,30 @@ The ToggleTeleportEnabled method is used to determine whether the teleporter wil

The ValidLocation method determines if the given target is a location that can be teleported to

#### ForceTeleport/1

> `public virtual void ForceTeleport(DestinationMarkerEventArgs teleportArgs)`
* Parameters
* `DestinationMarkerEventArgs teleportArgs` - The pseudo Destination Marker event for the teleport action.
* Returns
* _none_

The ForceTeleport/1 method forces the teleport to update position without needing to listen for a Destination Marker event.

#### ForceTeleport/3

> `public virtual void ForceTeleport(Transform target, Vector3 destinationPosition, Quaternion? destinationRotation = null)`
* Parameters
* `Transform target` - The Transform of the destination object.
* `Vector3 destinationPosition` - The world position to teleport to.
* `Quaternion? destinationRotation` - The world rotation to teleport to.
* Returns
* _none_

The ForceTeleport/3 method forces the teleport to update position without needing to listen for a Destination Marker event. It will build a destination marker out of the provided parameters.

### Example

`VRTK/Examples/004_CameraRig_BasicTeleport` uses the `VRTK_SimplePointer` script on the Controllers to initiate a laser pointer by pressing the `Touchpad` on the controller and when the laser pointer is deactivated (release the `Touchpad`) then the user is teleported to the location of the laser pointer tip as this is where the pointer destination marker position is set to.
Expand Down

0 comments on commit 2065a7f

Please sign in to comment.