- Home /
Question by
jorgeramosh31 · Sep 21, 2019 at 10:37 AM ·
raycastdirectionraycasthitmagic
Magic Leap Raycasting - Direction
Hi! I'm working with Magic Leap, and I'm trying to set an object direction using another direction between 2 raycasted points. I've been using this script but it doesn't get the right direction actually. Thanks in advance.
if (_controller.IsBumperDown == true && lastPressed == 1 && secondsCount >= 2)
{
Debug.Log("Segundo Presionado");
secondpoint = result.point;
var angle = (secondpoint - firstpoint).normalized.y;
Debug.Log("Angulo rotación:" + angle);
var rotation = Quaternion.Euler(0, angle, 0);
objToPlace.transform.localRotation = rotation;
objToPlace.SetActive(true);
}
Comment
Best Answer
Answer by WarmedxMints · Sep 21, 2019 at 11:06 AM
Use the quaternion LookRotation method. As it looks like you wish to just rotate on the y-axis, set the y value to the same or zero on both vectors before creating the rotation.
var p1 = firstPoint;
var p2 = result.point;
p1.y = 0;
p2.y = 0;
var targetRot = Quaternion.LookRotation(p2 - p1);
objToPlace.transform.rotation = targetRot;
objToPlace.SetActive(true);
Answer by jorgeramosh31 · Sep 21, 2019 at 02:40 PM
Thanks a lot man. Didn't try it that way. It works fine now.