Making an object go to ray.hitNormal

How come I keep getting: ‘str’ object has no attribute “worldPosition”? How do I make the object go to the ray hit position?

    laser = owner['laser']
    
    if ray.positive:
        laser.worldPosition = Vector (ray.hitPosition) + (Vector(ray.hitNormal) * .006)
        laser.alignAxisToVect(ray.hitNormal, 2)

Thanks

This means owner[‘laser’] is a string, not a KX_GameObject that you seem to be expecting. Check the code where you originally assign owner[‘laser’].

Thanks for that!

What kind of behavior are you looking for, if I may ask? Is this script supposed to find a target and go towards it?

Mobious said it.

owner[‘laser’] is a string object meaning it doesn’t have the worldPosition variable in its class.

An easy fix would be this:



laser = bge.logic.getCurrentScene().objects[owner['laser']];


Just use the string as the key for the objects dictionary.