- Home /
How to "rotate" a vector?
Hi. I'm making a isometric low-poly game. My camera is rotated by 45 degrees. If I use a raycast from camera to cursor and place cursor above the player it gives me vector (-0.7, 0, 0.7) because camera is rotated, so my top means top-left. I need to make this vector (0, 0, 1), is there a way of doing this? (It should work in all directions). Thanks!
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, mouseRayMask))
{
Debug.Log((hitInfo.point - transform.position).normalized);
}
Comment
Sure,
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, $$anonymous$$athf.Infinity, mouseRay$$anonymous$$ask))
{
Debug.Log((hitInfo.point - transform.position).normalized);
}
Best Answer
Answer by Xaverix · Oct 09, 2017 at 05:15 PM
Ok, i got this :)
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, mouseRayMask))
{
Debug.Log(Quaternion.Euler(new Vector3(0, 45, 0)) * (hitInfo.point - anim.transform.position).normalized);
}