Laser Effect

Hi!
I try to write a code that display a laser effect and i wrote this
http://www.allevo.net78.net/laser.tar.gz

but some tube goes out from the cube… and i don’t know if it is deleted by laserCollision method.

proposals to improve the code?

thanks for all!!

PS: the use a interval instead a task to move, is the code improved ?
And if i remove the top and the bottom face of tube ?

On line 72, where you are creating the collision segment collision object, you set the into collide mask. Since the segments are being used as the colliders, you want to set the from collision mask on them, and turn the into collision mask to all off. Like so:

            tube_node = tube.attachNewNode(CollisionNode('laserTube'))
            tube_node.node().addSolid(CollisionSegment(-2, 0, 0, 2, 0, 0))
            tube_node.node().setFromCollideMask(BitMask32.bit(0))
            tube_node.node().setIntoCollideMask(BitMask32.allOff())
            self.laserTraverser.addCollider(tube_node, self.laserHandler)

You also need to make sure the into collision mask on the cube is set correctly, and that the egg file contains collision geometry.

tube_node.node().setFromCollideMask(BitMask32.bit(0))
tube_node.node().setIntoCollideMask(BitMask32.allOff())

thanks!

UPDATE:
i find a better solution
http://www.allevo.net78.net/laser1.tar.gz
use CollisionHandlerQueue with CollisionRay to find the length and position of each beam (a tube for each one)

with 8 laser generator in the screen (look at they together) there’s a 70 FPS

Is there a best solution??
thanks for all!!! :laughing: