Hi there,
There are some tutorials for this but only without VR.
I had a lot of problems to get the position from the collider and raycast.
I copied a part from the OVR Physics Raycast script.
When I try to run the script, nothing happens.
Can you help me?
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class drawingdots : OVRPhysicsRaycaster
{
[Tooltip("Transform for the dots.")]
public Transform dot = null;
// int primary; // 0 = right controller ; 1= left controller
int primary;
private List<Vector3> PointList;
private Vector3 CollisionPos;
// Start is called before the first frame update
void Start()
{
if(OVRInput.IsControllerConnected(OVRInput.Controller.RTrackedRemote))
{
primary = 0;
}
else if(OVRInput.IsControllerConnected(OVRInput.Controller.LTrackedRemote))
{
primary = 1;
}
}
public Vector3 get_CollisionPos(PointerEventData eventData)
{
//CollisionPos = Position where the ray hits the object
//calculate the positions
ControllerSelection.RayPointerEventData rayPointerEventData = eventData as ControllerSelection.RayPointerEventData;
var ray = rayPointerEventData.worldSpaceRay;
float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;
var hits = Physics.RaycastAll(ray, dist, finalEventMask);
if (hits.Length > 1)
System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
if (hits.Length != 0)
{
CollisionPos = hits[0].point;
}
return CollisionPos;
}
// create particles and save them in the pointlist
void CreateParticle(PointerEventData eventData, Transform dot)
{
Vector3 position = get_CollisionPos(eventData);
PointList.Add(position);
//create particle with the position
Instantiate(dot, position, Quaternion.identity);
}
// debug log information about the position of collision between object and raycast
void LoggInfo(PointerEventData eventData)
{
Vector3 position = get_CollisionPos(eventData);
// function where all log files are saved
string numbers = position.ToString();
Debug.Log("Position: " + numbers);
}
// Update is called once per frame
//get location where ray hits objects
//create particle
void Update()
{
if (primary == 1)
{
if (OVRInput.Get(OVRInput.Button.PrimaryHandTrigger))
{
CreateParticle(eventData, dot);
}
}
else if (primary == 0)
{
if (OVRInput.Get(OVRInput.Button.SecondaryHandTrigger))
{
CreateParticle(eventData, dot);
}
}
LoggInfo(eventData);
}
}