Tutorial: Mesh Collision
Last updated
Was this helpful?
Was this helpful?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NRKernal;
public class Shoot : MonoBehaviour
{
public float moveSpeed = 10f;
public GameObject shootPos;
public float force = 1000;
public GameObject ballPrefab;
Vector3 targetObjectNextPosition;
RaycastHit hit;
void FixedUpdate()
{
if (NRInput.GetButtonDown(ControllerButton.TRIGGER))
{
var handControllerAnchor =
NRInput.DomainHand == ControllerHandEnum.Left
? ControllerAnchorEnum.LeftLaserAnchor
: ControllerAnchorEnum.RightLaserAnchor;
Transform laserAnchor = NRInput.AnchorsHelper.GetAnchor(
NRInput.RaycastMode == RaycastModeEnum.Gaze
? ControllerAnchorEnum.GazePoseTrackerAnchor
: handControllerAnchor
);
Ray ray =new Ray(laserAnchor.transform.position, laserAnchor.transform.forward);
Rigidbody ball = Instantiate(ballPrefab, shootPos.transform.position, Quaternion.identity).GetComponent<Rigidbody>() as Rigidbody;
ball.AddForce(force * ray.direction);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class sphere : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Invoke("DelayDestroy", 10); // * destroy the prefab after 10 seconds
}
// Update is called once per frame
void DelayDestroy()
{
Destroy(this.gameObject);
}
}