Search code examples
c#unity-game-enginedaydream

how to get vector pointing in Laser direction?


I need to shoot elements form the controller, so ideally they'd go in the direction of the Laser pointer you can see and move with the controller.

This is what I need:

GameObject controllerLaser;
controllerLaser = GameObject.Find("VRMain/GvrControllerPointer/Laser");

Debug.DrawRay(firingSource.transform.position, firingDirection * 50, Color.red);

I need that red vector pointing and moving exactly like the Laser.


Solution

  • I managed to do it..

    GameObject controllerLaser;
    controllerLaser = GameObject.Find("VRMain/GvrControllerPointer/Laser");
    
    //The Laser GameObject has the Reticle as its child, so you can make a vector
    //that goes from the controller position to the reticle
    firingDirection = controllerLaser.transform.GetChild(0).position - controller.transform.position;
    
    //For firing the bullet (bonus)
    bulletRB.velocity = firingDirection * bulletVelocity;
    
    Debug.DrawRay(firingSource.transform.position, firingDirection * 50, Color.red);