Skip to content

Commit

Permalink
fix(Teleport): reapply height offset on teleport
Browse files Browse the repository at this point in the history
The height offset given when casting the ray on the height adjust
teleport also needs to be reapplied to the final y position otherwise
the destination y is not correct as it is minus the height adjust
value given to the raycast down.
  • Loading branch information
thestonefox committed Jul 13, 2016
1 parent 96de76b commit 0b01d8c
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -44,14 +44,15 @@ protected override Vector3 GetNewPosition(Vector3 tipPosition, Transform target)

private float GetTeleportY(Transform target, Vector3 tipPosition)
{
float newY = this.transform.position.y;
var newY = this.transform.position.y;
var heightOffset = 0.1f;
//Check to see if the tip is on top of an object
var rayStartPositionOffset = Vector3.up * 0.1f;
var rayStartPositionOffset = Vector3.up * heightOffset;
var ray = new Ray(tipPosition + rayStartPositionOffset, -transform.up);
RaycastHit rayCollidedWith;
if (target && Physics.Raycast(ray, out rayCollidedWith))
{
newY = tipPosition.y - rayCollidedWith.distance;
newY = (tipPosition.y - rayCollidedWith.distance) + heightOffset;
}
return newY;
}
Expand Down

0 comments on commit 0b01d8c

Please sign in to comment.