Question by
gmamafilms · Aug 15, 2016 at 06:19 PM ·
vrparticle systemraycasthitteleportingcalculate
Look Teleport: Particle System
I made a teleport script so that when you click you teleport to the object your looking at, but I want to make a particle system kind of like the orbital strike from battle front where there is a circle that follows where you look and can tell you where you're going to teleport.
using UnityEngine; using System.Collections;
public class LookTele : MonoBehaviour {
private RaycastHit lastRaycastHit;
public AudioClip audioClip;
// Use this for initialization
void Start () {
Cursor.visible = false;
}
private GameObject GetLookedAtObject(){
Vector3 origin = transform.position;
Vector3 direction = Camera.main.transform.forward;
float range = 1000;
if (Physics.Raycast (origin, direction, out lastRaycastHit, range))
return lastRaycastHit.collider.gameObject;
else
return null;
}
private void TeleportToLookAt(){
transform.position = lastRaycastHit.point + lastRaycastHit.normal * 2;
if (audioClip != null)
AudioSource.PlayClipAtPoint (audioClip, transform.position);
}
// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown ("Fire1"))
if (GetLookedAtObject () != null)
TeleportToLookAt ();
}
}
any help is great.
Comment
Your answer
Follow this Question
Related Questions
How to make a laser pointer with WebXR 0 Answers
(CRASH) how do I fix my teleporter code? 2 Answers
SteamVR Teleport onto moving object 1 Answer
VR controller collision with objects 0 Answers
Help with pour effect script not registering in SteamVR? 0 Answers