am trying to setup a simple obstacle avoidance, using a ray sensor facing forward direction of an object. If this forward sensor hits something i want to send two raycast to the left and right of the hit position.
Am probably having 2 problems, understanding what it means to use vectors instead of objects position with Raycast. And rotating a vector.
Here's my code
def Raycastor(cont):
obj = cont.owner
sRay = cont.sensors['sRay']
if sRay.positive:
# Debug render ray sensor (Y)
render.drawLine( obj.worldPosition, sRay.hitPosition, [0,255,0])
# can get the vector between object and hit position
vectTo = obj.getVectTo(sRay.hitPosition)
# getting the vector from the list
vectTo = vectTo[1]
hit_obj, hit_pos, _ = obj.rayCast( vectTo[1], obj)
Now i don't know how to rotate that vector, tried
matrix = mathutils.Matrix.Rotation(math.pi / 2, 4, "Z")
vectTo[1].rotate(matrix)
and many other things but i usually end with a matrix, quaternion or tuples that i don't know how to use them with raycast or render.drawline for debugging.
So, for raycasting with vectors, does those vectors needs to be vectors pointing from objects to the origin ?
And is there a smart way of rotating a vector by some degrees (or whatever) ?
Any help appreciated.