WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Collision Help (https://forum.worldviz.com/showthread.php?t=4553)

uncleseano 04-17-2013 04:16 AM

Collision Help
 
Heya I need help trying to get a ball to collide properly with a box and print out a generic statement. Need help badly thanks

boxes = []
balls = []

for i in range(GRID_WIDTH):
boxes.append([])
for j in range(GRID_HEIGHT):
#Add a box model
box = viz.add('box.wrl',cache=viz.CACHE_CLONE)
#Use the boxes bounding box for collisions
box.collideBox()
#Add the box to the list
boxes[i].append(box)

for x in range(MAX_BALLS):
#Add a ball model
ball = viz.add('ball.wrl',scale=(3,3,3),cache=viz.CACHE_C LONE)
#The balls collision will be represented by the bounding sphere of the ball
ball.collideSphere()
ball.enable( viz.COLLIDE_NOTIFY )
#Add the body to the list
balls.append(ball)

#Create a generator this will loop through the balls
nextBall = viz.cycle(balls)

breakerBox = viz.add('box.wrl')
breakerBox.collideBox()
breakerBox.setCenter(0,0,-2)

greenBox = viz.add('boxee.wrl')
greenBox.collideBox()
#greenBox.enable( viz.COLLIDE_NOTIFY )
greenBox.setPosition(2,0,-1)

#This function is called when a collision occurs
def ballBoxCollision(e):
if ball.intersect == greenBox.intersect:
print 'collision'
#if e.ball in balls == ground:

viz.callback( viz.COLLIDE_BEGIN_EVENT, ballBoxCollision )

Jeff 04-18-2013 10:37 AM

Please post code using the code tags to preserve the indentation. You can find out which Vizard nodes collided from the event object e passed to the collision callback function. Take a look at the Event Reference page for more information.

If viz.COLLIDE_NOTIFY is enabled on the balls you can check to see if e.obj2 is the greenBox and you'll know a ball collided with it.


All times are GMT -7. The time now is 01:26 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC