Vizard 7 » Tutorials & Examples » Example scripts » Viewpoint » Viewpoint collision
7.6

Viewpoint Collision

\examples\viewpointCollision\collision.py

This script shows how to detect collisions between the viewer and objects in the world.

"""
This script demonstrates how to use collision detection.
Vizard will automatically handle collisions with the viewpoint.
When the viewpoint collides with an object, the script will print out "Collided"
"""
import viz

viz.setMultiSample(4)
viz.fov(60)
viz.go()

import vizinfo
vizinfo.InfoPanel()

#Add the maze environment
maze = viz.addChild('maze.osgb')

#Turn on collision
viz.collision(viz.ON)

#This function is called when a collision occurs
def mycollision(info):
    print('Collided')

#Create a callback for a collision event
viz.callback(viz.COLLISION_EVENT, mycollision)