Casting a ray 45 degress to the right?

How can I cast a ray 45 degrees to the objects right. I am just starting to properly learn vector/matrix math and what I came up with doesn’t seem to work.

Thanks-
Ex

I, too, would like to know this. I think that you can get a local +Y ray by adding the second component of the local orientation ( [1] ) to the current position of the object, but beyond that, I’m not too sure.

add an empty, parent it to the Object. use Raycast or RaycastTo this empty.

Yeah, that is a solution, but that can get hairy if you need several 45 degree castings.

If you take a vector from the object to some point infront of the object and multiply it by a rotation matrix you can get a position to cast to:

import bge
from mathutils import *

own = bge.logic.getCurrentController().owner

# construct a matrix to rotate a vector 45 degrees clockwise (0.7 rads) around the objects z axis
rotation = Matrix.Rotation(-0.785, 4, own.worldOrientation[2]) 

ray_dest = own.worldPosition + (own.worldOrientation[1].copy().normalise() * rotation)

own.rayCastTo(own, ray_dest blah blah)