I'm working on a targeting system for my 2d game. But I want to see the object in isometric perspective. My calculation is correct for 2d objects but it doesn't work for rotated in x axis objects.

I want to see yellow line which is rotated in x axis to look towards directly to red circle in 2d orthographic camera. I need to calculate angle between yellow and white lines and loss of length due to rotation.

private void OnDrawGizmos()
            var isometricAngle = math.radians(54.736f);
            var difference = _target.position - _source.position;
            var whiteLineDirection = difference.normalized;
            var yellowLineDirection = math.mul(quaternion.Euler(isometricAngle, 0, 0), whiteLineDirection);
            var distance = difference.magnitude;
            Gizmos.color = Color.white;
            Gizmos.DrawRay(_source.position, whiteLineDirection * distance);
            Gizmos.color = Color.yellow;
            Gizmos.DrawRay(_source.position, yellowLineDirection * distance);
  • green circle: player with rotation in eular(0, 0, 0)
  • yellow line: effect with rotation in eular(54.736, 0, 0)
  • white line: debug line with rotation in eular(0, 0, 0)
  • red circle: enemy with rotation in eular(0, 0, 0)

enter image description here

enter image description here

  • \$\begingroup\$ Could you add a bit more description on what you want to achieve? Right now the question doesn't even contain a "question" sentence. \$\endgroup\$
    – datacube
    Sep 8, 2023 at 6:34
  • \$\begingroup\$ Sorry for the bad explanation. I hope it's clear now \$\endgroup\$
    – 26.565
    Sep 8, 2023 at 7:33
  • \$\begingroup\$ My usual approach would be to store and manipulate all objects in orthogonal and non-foreshortened world coordinates, then apply the isometric perspective in the conversion to screen space (e.g. via the Camera in Unity). This separation of the underlying behaviour model from the particulars of the view/representation helps simplify a lot of systems. \$\endgroup\$
    – DMGregory
    Sep 8, 2023 at 21:44
  • \$\begingroup\$ Thank you for your comment. That approach is not bad but unfortunately, I can't use in my case. \$\endgroup\$
    – 26.565
    Sep 9, 2023 at 8:21


You must log in to answer this question.

Browse other questions tagged .