1
$\begingroup$

I'm trying to simulate laserbeams going through movable mirrors to see where they end up on some screen depending on the orientation of the mirrors. So I figured that I could use raycast from the laser source to the mirrors and from the location and normal vector of the mirror cast a new ray in the reflected direction an so on.

But I can't get the raycast to work. I have previously used the raycast from 3Dview to objects from the template with success. But I can't find any good explanation or documentation on the basic object.ray_cast() function.

import bpy
import mathutils

source = bpy.data.objects.get('Source')

location  = source.location
direction = mathutils.Vector([0 , -1 , 0])

ray_succes, ray_object, ray_normal = source.ray_cast(location, direction)

But I get this error:

enter image description here

So I lack the basic understanding of how the function works. Any explanation, good answered questions, tutorials, documentation would be really appreciated. I'm open to alternative ways to shine light beams through mirrors which I can then move and rotate with python code.

$\endgroup$
2
  • 2
    $\begingroup$ Object.ray_cast has for a long time returned a tuple of 4 results,as shown in Operator Modal View3D Raycast template, these are success, location, normal, face_index The error (please copy & paste as text from system console in future) displayed is informing you that you only have 3. Hence Question Closed as dupe.. Somewhat related blender.stackexchange.com/a/91019/15543 $\endgroup$
    – batFINGER
    Mar 8, 2021 at 17:06
  • $\begingroup$ Hmm. I messed up the three outputs, so @batFINGER helped. But I'm not really sure about why this is a object method when I need to supply a ray-origin as well. And I am confused about local coordinates vs world coordinates. $\endgroup$
    – DrDress
    Mar 8, 2021 at 20:30

0

Browse other questions tagged .