WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-08-2009, 06:24 AM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
Collision

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.
HTML Code:
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,
Reply With Quote
  #2  
Old 04-08-2009, 04:19 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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
Reply With Quote
  #3  
Old 04-09-2009, 08:35 AM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
Jeff I tried with many ways; below is my modification but does not work
HTML Code:
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,
Reply With Quote
  #4  
Old 04-09-2009, 09:54 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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.
Code:
avatar.disable(viz.DYNAMICS)
balloon.disable(viz.DYNAMICS)
Reply With Quote
  #5  
Old 04-09-2009, 05:54 PM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
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
HTML Code:
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)
Reply With Quote
  #6  
Old 04-13-2009, 01:21 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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.
Code:
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
Code:
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
Reply With Quote
  #7  
Old 04-21-2009, 03:57 AM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
HI Jeff ,Thank you very much for your help.
I cannot understand the collision in vizard although it looks very easy!
I have struggled to detect the collision event by more than one way but all them did not work . I followed Farshizzo’s example on this link
http://forum.worldviz.com/showthread.php?p=5599
but did not work with my code
HTML 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!
Reply With Quote
  #8  
Old 04-21-2009, 12:59 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
obj1 is the node that generated the event and obj2 is the node that obj1 collided with
Reply With Quote
  #9  
Old 04-27-2009, 03:42 AM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
it works fine. but i am trying to use the following lines to see the score
HTML Code:
data = viz.Data()
yield viztask.waitEvent( viz.COLLISION_EVENT, data )
but this does not work with the following event detection
HTML Code:
def onCollideBegin(e):
	if e.obj1 == rHandBox:
		if e.obj2 == box:
			box.color(colors.next())
viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegin)
any idea would be appreciated
Reply With Quote
  #10  
Old 04-28-2009, 02:50 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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.
Reply With Quote
  #11  
Old 04-29-2009, 07:34 AM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
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)
Any help would be appreciated
Thanks,
Attached Files
File Type: zip test1.zip (2.5 KB, 833 views)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Collision detection with specific models just alex Vizard 1 02-06-2009 11:02 AM
Collision Detection and Nearest Point to Probe xabbu Vizard 2 01-06-2009 03:01 AM
Collision with child nodes rubberpimple Vizard 4 09-17-2008 04:27 PM
Collision detection with haptic pen mjabon Vizard 3 01-17-2008 06:35 PM
collision events trigger Eunice Vizard 1 01-03-2006 10:39 AM


All times are GMT -7. The time now is 02:42 PM.


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