I’ve been searching about this for the past 2 hours and still didn’t find any solution. Anyone here knows how to convert this? Any kind of help is very appreciated!
More info: When I rotate the game object the gizmos ray does not rotate with the game object as it is supposed to(-360 to 360 degrees), instead, it just rotates until 1 or -1 degrees…
Here’s my script:
using UnityEngine;
[ExecuteInEditMode]
public class GrabbingSystem : MonoBehaviour
{
[SerializeField] private Transform Player;
[SerializeField] private Transform Camera;
private Vector3 result;
private void Update()
{
float y = Player.transform.rotation.y;
float x = Camera.transform.rotation.x;
Debug.Log(x);
result = Vector3.forward * 10f;
var rot = Quaternion.Euler(0, y, 0) * Quaternion.Euler(x, 0, 0);
result = rot * result;
}
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawLine(Player.position, Player.position + result);
}
You’re mixing up the quaternion with the Euler angles. Lines 12-13 should use .eulerAngles.x/y, not the quaternion’s .x/y.
But, splitting up Euler angles by component is a Bad Idea ™, because any one X/Y/Z component of a Euler angle is actually pretty meaningless without the other two. Here’s a video I made illustrating the many problems with Euler angles. I’m not sure what the rest of your setup is, but you’ll probably be better off using some transform.forward or other with Quaternion.LookDirection to determine your grabber’s facing.