portal interaction and VR body
This commit is contained in:
@@ -5,113 +5,106 @@ using UnityEngine;
|
||||
public class ActionGestureInteraction : MonoBehaviour
|
||||
{
|
||||
public List<GameObject> objects;
|
||||
public Camera playerCamera;
|
||||
private Vector3 destination;
|
||||
|
||||
private Transform rightHandTransform;
|
||||
public Transform rightHandTransform;
|
||||
private GameObject player;
|
||||
|
||||
/**public int blinkUses;
|
||||
public float blinkCooldown, blinkDistance, blinkSpeed, blinkDestinationMultiplier;
|
||||
public LayerMask blinkLayerMask;**/
|
||||
public float projectileSpeed = 30;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
player = GameObject.Find("XR Origin");
|
||||
rightHandTransform = player.transform.Find("Camera Offset").Find("RightHand Controller").transform;
|
||||
player = gameObject;
|
||||
}
|
||||
|
||||
public void PerformAction(string action)
|
||||
{
|
||||
//Debug.Log(action);
|
||||
//if (action == "Blink")
|
||||
//{
|
||||
//BlinkCast(); [DEPRECATED]
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
Debug.Log(action);
|
||||
if (action == "Portal")
|
||||
{
|
||||
// Raycast to find portal were looking at.
|
||||
var nearestPortal = FindPortalInFront();
|
||||
Debug.Log(nearestPortal);
|
||||
EnableDisablePortal(nearestPortal);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in objects)
|
||||
{
|
||||
if (item.name == action)
|
||||
if (item.name == action && action == "IceBolt")
|
||||
{
|
||||
Instantiate(item, rightHandTransform.position, Quaternion.identity);
|
||||
|
||||
ShootProjectile();
|
||||
InstantiateIceBolt(item);
|
||||
}
|
||||
|
||||
}
|
||||
//}
|
||||
}
|
||||
/**
|
||||
int maxUses;
|
||||
float cooldownTimer;
|
||||
bool blinking = false;
|
||||
Vector3 destination;
|
||||
**/
|
||||
private void Update()
|
||||
{
|
||||
// Blink cooldown action;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** [DEPRECATED]
|
||||
void BlinkCast()
|
||||
{
|
||||
Transform cameraTransform = Camera.main.transform;
|
||||
Transform playerTransform = player.transform;
|
||||
ParticleSystem blinkTrail = player.transform.Find("BlinkTrail").GetComponent<ParticleSystem>();
|
||||
maxUses = blinkUses;
|
||||
cooldownTimer = blinkCooldown;
|
||||
|
||||
Blink();
|
||||
if (blinkUses < maxUses)
|
||||
{
|
||||
if (cooldownTimer > 0)
|
||||
{
|
||||
cooldownTimer -= Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
blinkUses += 1;
|
||||
cooldownTimer = blinkCooldown;
|
||||
}
|
||||
|
||||
if (blinking)
|
||||
{
|
||||
|
||||
var dist = Vector3.Distance(playerTransform.position, destination);
|
||||
if (dist > 0.5f)
|
||||
if (item.name == action && action == "IceWall")
|
||||
{
|
||||
Debug.Log(Time.deltaTime * blinkSpeed);
|
||||
playerTransform.position = Vector3.MoveTowards(playerTransform.position, destination, blinkDistance);
|
||||
// Make ice wall appear from below to block incoming projectiles
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void EnableDisablePortal(GameObject portal)
|
||||
{
|
||||
// Did the raycast catch a portal in front of us?
|
||||
if (portal != null)
|
||||
{
|
||||
var distance = Vector3.Distance(portal.transform.position, this.transform.position);
|
||||
Debug.Log(distance);
|
||||
// Is the portal within a reasonable distance?
|
||||
if (distance <= 10.0f)
|
||||
{
|
||||
var portalVFX = portal.transform.Find("PortalFX");
|
||||
var portalTrigger = portal.transform.Find("Portal");
|
||||
// if the nearest portal is already enabled, then disable, else enable.
|
||||
if (portalVFX.gameObject.activeInHierarchy)
|
||||
{
|
||||
portalVFX.gameObject.SetActive(false);
|
||||
portalTrigger.gameObject.GetComponent<PortalTeleporter>().enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
blinking = false;
|
||||
portalVFX.gameObject.SetActive(true);
|
||||
portalTrigger.gameObject.GetComponent<PortalTeleporter>().enabled =true;
|
||||
}
|
||||
}
|
||||
}
|
||||
void Blink()
|
||||
{
|
||||
if (blinkUses > 0)
|
||||
{
|
||||
blinkUses -= 1;
|
||||
blinkTrail.Play();
|
||||
//RaycastHit hit;
|
||||
if (Physics.Raycast(playerTransform.position, playerTransform.forward, out hit, blinkDistance, blinkLayerMask))
|
||||
{
|
||||
Debug.Log(hit.transform.name);
|
||||
destination = hit.point * blinkDestinationMultiplier;
|
||||
}
|
||||
else
|
||||
{
|
||||
destination = (cameraTransform.position + cameraTransform.forward.normalized * blinkDistance) * blinkDestinationMultiplier;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
destination.y += Camera.main.transform.position.y;
|
||||
blinking = true;
|
||||
GameObject FindPortalInFront()
|
||||
{
|
||||
Ray ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
|
||||
RaycastHit hit;
|
||||
LayerMask playerLayerMask = LayerMask.GetMask("Player");
|
||||
if (Physics.Raycast(ray, out hit, playerLayerMask))
|
||||
{
|
||||
|
||||
if (hit.transform.gameObject.transform.root.CompareTag("Portal"))
|
||||
{
|
||||
return hit.transform.gameObject.transform.root.gameObject;
|
||||
}
|
||||
}
|
||||
}**/
|
||||
return null;
|
||||
}
|
||||
|
||||
void ShootProjectile()
|
||||
{
|
||||
Ray ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit))
|
||||
{
|
||||
destination = hit.point;
|
||||
}
|
||||
else
|
||||
{
|
||||
destination = ray.GetPoint(1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InstantiateIceBolt(GameObject item)
|
||||
{
|
||||
var projectileObj = Instantiate(item, rightHandTransform.position, Quaternion.identity) as GameObject;
|
||||
projectileObj.GetComponent<Rigidbody>().velocity = (destination - rightHandTransform.position).normalized * projectileSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using UnityEngine.Events;
|
||||
|
||||
public class GestureRecognizer : MonoBehaviour
|
||||
{
|
||||
|
||||
public InputDevice rightHandController;
|
||||
public XRNode rightHandSource;
|
||||
public InputHelpers.Button rightInputButton;
|
||||
public InputHelpers.Button rightControlButton;
|
||||
@@ -60,11 +60,13 @@ public class GestureRecognizer : MonoBehaviour
|
||||
if (!isMoving && startGesture)
|
||||
{
|
||||
StartMovement();
|
||||
StartCoroutine("Haptics");
|
||||
}
|
||||
// Ending the movement
|
||||
else if (isMoving && !startGesture)
|
||||
{
|
||||
EndMovement();
|
||||
StopCoroutine("Haptics");
|
||||
}
|
||||
// Updating the movement
|
||||
else if (isMoving && startGesture)
|
||||
@@ -72,6 +74,14 @@ public class GestureRecognizer : MonoBehaviour
|
||||
UpdateMovement();
|
||||
}
|
||||
}
|
||||
// Still needs to be tested
|
||||
IEnumerator Haptics()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
rightHandController.SendHapticImpulse(0u, 0.7f, 0.2f);
|
||||
}
|
||||
}
|
||||
|
||||
void StartMovement()
|
||||
{
|
||||
|
||||
@@ -13,7 +13,12 @@ public class SpawnerGestureInteraction : MonoBehaviour
|
||||
|
||||
foreach (var item in objects)
|
||||
{
|
||||
if (item.name == objectName)
|
||||
Debug.Log(item);
|
||||
if (item.name == "IceBolt")
|
||||
{
|
||||
Instantiate(item, rightHandTransform.position, Quaternion.identity, rightHandTransform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Instantiate(item, rightHandTransform.position, Quaternion.identity);
|
||||
Debug.Log(objectName);
|
||||
|
||||
Reference in New Issue
Block a user