Last active
July 5, 2017 15:58
-
-
Save paulhayes/d7a0a8e3c021aa716d8590f84bb207c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class TeleportTarget : MonoBehaviour | |
| { | |
| public string button = "Fire1"; | |
| public Transform lookDirection; | |
| public Transform target; | |
| public float maxSlopeAngle = 30; | |
| public void Update() | |
| { | |
| if( Input.GetButton(button) ){ | |
| Teleport(); | |
| } | |
| } | |
| void Teleport() | |
| { | |
| RaycastHit hitInfo; | |
| bool hit = Physics.Raycast(lookDirection.position, lookDirection.forward, out hitInfo); | |
| if( hit ){ | |
| float currentSlope = Vector3.Dot( hitInfo.normal, Vector3.up ); | |
| float maxSlope = Mathf.Cos(maxSlopeAngle*Mathf.Deg2Rad); | |
| if( maxSlope > currentSlope ){ | |
| target.position = hitInfo.point; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment