PDA

View Full Version : Collision


Moh200jo
04-08-2009, 06:24 AM
Hi, This code is trying to not allow the avatar to walk through the court’s wall and balloon.
May my collision statement for avatar is wrong, but this what I have found in tutorials.
import viz

viz.go()
viz.phys.enable()
court= viz.add( 'court.ive' )
court.setPosition(0,0,15)
viz.collision()
balloon=viz.add('balloon.ive')
balloon.setScale(7,7,7)
balloon.setPosition(0,0,8)
avatar=viz.add('vcc_female.cfg')
walk_Forward = vizact.walkTo([0,0,20])
avatar.addAction(walk_Forward)
avatar.collideBox(viz.COLLIDE_NOTIFY)
avatar.disable(viz.DYNAMICS)
Any suggestion would be appreciated.
Thanks,

Jeff
04-08-2009, 04:19 PM
If you want a collision with the balloon to occur you will need to add a collision shape to it and enable dynamics on the avatar. You could manually check to see if the avatar is near a wall and if it is end the walking action

Moh200jo
04-09-2009, 08:35 AM
Jeff I tried with many ways; below is my modification but does not work :confused:
import viz

viz.go()
viz.phys.enable()
court= viz.add( 'court.ive' )
court.setPosition(0,0,15)
viz.collision()
balloon=viz.add('balloon.ive')
balloon.setScale(7,7,7)
balloon.setPosition(0,0,8)
avatar=viz.add('vcc_female.cfg')
walk_Forward = vizact.walkTo([0,0,20])
avatar.addAction(walk_Forward)
balloon.collideMesh()
avatar.disable(viz.DYNAMICS)
balloon.disable(viz.DYNAMICS)
Thanks Jeff,

Jeff
04-09-2009, 09:54 AM
If you want the balloon to react to the collision you can not use the collideMesh, you'll have to use a different collide shape. Collide meshes do not react to forces. Also you have dynamics disabled on both the avatar and balloon. So you can remove these lines.
avatar.disable(viz.DYNAMICS)
balloon.disable(viz.DYNAMICS)

Moh200jo
04-09-2009, 05:54 PM
well, JEFF, I have tried to follow the gallery example in tutorial as well as your advices. the collision works around main-view and all stuff react including avatar. but the avatar responses as an object(like the balloon).(avatar still walking through the wall and balloon)
any help would be appreciated
import viz

viz.go()
#viz.phys.enable()
court= viz.add( 'court.ive' )
court.setPosition(0,0,15)
viz.collision()
avatar=viz.add('vcc_female.cfg')
#view=viz.MainView
#link=viz.link(view,avatar)
#link.preTrans([0,-1.5,4])
#viz.MainView.collision()

balloons=[]
for i in range (0,4,3):
balloon=viz.add('balloon.ive')
balloon.setScale(7,7,7)
balloon.setPosition(0,0,i+5)
balloons.append(balloon)

walk_Forward = vizact.walkTo([5,0,15])
avatar.addAction(walk_Forward)
balloon.collideSphere()
#avatar.disable(viz.COLLISION)

Jeff
04-13-2009, 01:21 PM
Here's an example with an avatar and a ball. You need to have collision shapes for both objects to have a collision. Your code did not have a collision shape for the avatar.
import viz
viz.go()

viz.phys.enable()

court = viz.add('court.ive')
court.collidePlane()

avatar=viz.add('vcc_male.cfg', pos = [0,0,3])
shape = avatar.collideBox()
shape.setDensity(10)

ball = viz.add('ball.wrl', pos = [0,0,7])
ball.collideSphere()

walk = vizact.walkTo([0,0,10])
vizact.onkeydown(' ', avatar.addAction, walk)

When you use viz.collision(viz.ON) that only turns on collision detection for the viewpoint.
If you want to stop the avatar from walking through the wall you could end the walkto action when the avatar is near the edge of the room

Moh200jo
04-21-2009, 03:57 AM
HI Jeff ,Thank you very much for your help.
I cannot understand the collision in vizard although it looks very easy! :confused:
I have struggled to detect the collision event by more than one way but all them did not work :mad:. I followed Farshizzo’s example on this link
http://forum.worldviz.com/showthread.php?p=5599
but did not work with my code
def oncollide(e):
if e.obj1 in ball:
print 'colllision'
viz.callback(viz.COLLIDE_BEGIN_EVENT,oncollide)
May I ask here... how can I know who is e.obj1 1?
Any suggestion would be appreciated!

Jeff
04-21-2009, 12:59 PM
obj1 is the node that generated the event and obj2 is the node that obj1 collided with

Moh200jo
04-27-2009, 03:42 AM
it works fine. but i am trying to use the following lines to see the score
data = viz.Data()
yield viztask.waitEvent( viz.COLLISION_EVENT, data )

but this does not work with the following event detection
def onCollideBegin(e):
if e.obj1 == rHandBox:
if e.obj2 == box:
box.color(colors.next())
viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegi n)
any idea would be appreciated

Jeff
04-28-2009, 02:50 PM
WHat do you mean by see the score, how many collisions have occured?
I'm not sure how you are using your task function with this.

Moh200jo
04-29-2009, 07:34 AM
Well, I have attached with this thread a sample of what I am trying to use. Indeed, I am using exactly the tasks example in vizard teacher book.
In this code you will see 2 main faults which are the collision and score (I tried many ways with the score and at then I decided to use the example, however, all ways I tried did not work):mad:
Any help would be appreciated
Thanks,