I cant figure out why my object still moves in x and z axis while dragging. I suspect that the transform uses the object oriantationaxis and not the world ones(the object is rotated). If this may be the problem how can i change the transform oriantation in my code?
private Vector3 screenPoint;
private Vector3 offset;
void Start()
{
}
void Update()
{
}
void OnMouseDown()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, 1000f, 1 << 9))
{
screenPoint = hitInfo.point;
//currentPlaceableObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
}
screenPoint = Camera.main.WorldToScreenPoint(transform.position);
offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
GameObject.Find(“CameraRig”).gameObject.GetComponent().enabled = false;
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
private void OnMouseUp()
{
GameObject.Find(“CameraRig”).gameObject.GetComponent().enabled = true;
}