Hello, I would like to shoot a ray forward, at an angle downward, from an object. I’ve tried the following code, but it just tilts the ray very slightly to the side. Any ideas what I can do? The ray must be at the same angle from the object, regardless of which way up it is.
Debug.DrawRay(transform.position, Quaternion.Euler(45f, 0, 0f) * transform.forward)
you can use
(transform.forward + transform.down).normalized to get a vector pointing 45° down. This uses the down vector from the objects point of view.
If the transform is tilted, then the vector will also be tilted.
I tried the code and it works for me, even with non-uniform scaled transforms…
Is it possible that you have set
Gizmos.matrix prior to this draw? If so, just reset it to
Matrix4x4.identity, otherwise no clue.