![]() |
|
#1
|
|||
|
|||
This seems to work, I'll try backing up a few steps and recreate this code in my model.
I added male.disable(viz.DYNAMICS), because else the avatar looks very blurry (drawing error or so?) AlsoI added gravity and a mousedriven walkto to see how it works. I'll try to incorporate it into my model tomorrow. But if anyone has anymore bright ideas how to detect collision with low cpu usage, please share! Here's the changed code: Code:
import viz viz.go() viz.MainView.setPosition( 0, 2, -5 ) viz.phys.enable() viz.phys.setGravity(0,-10,0) viz.setMouseOverride() ground = viz.add( 'tut_ground.wrl' ) ground.collidePlane() logo = viz.add('logo.wrl') logo.collideMesh() logo.disable( viz.DYNAMICS ) ball = viz.add('ball.wrl') g=ball.collideSphere() male = viz.add( 'male.cfg' ) male.translate( 0, 1, 4 ) male.collideBox() male.disable(viz.DYNAMICS) male.addAction( vizact.walkto( 0, 0, 0 ) ) male.enable( viz.COLLIDE_NOTIFY ) def onCollide(e): if e.obj2 == logo: print 'logo collide' elif e.obj2 == ground: print 'ground collide' elif e.obj2 == ball: print 'ball collide' viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide ) def onmousedown(button): if button == viz.MOUSEBUTTON_LEFT: info = viz.pick(1) if info.valid and info.object == ground: walk = vizact.walkto(info.point[0],0,info.point[2]) male.runAction(walk) viz.callback(viz.MOUSEDOWN_EVENT,onmousedown) |
#2
|
|||
|
|||
I'm going mad....
I added a collidemesh to the scene objects, but I'm not sure that that went correctly, because I have a lot of objects with the same name and Vizard does not have a wildcard option to search all the children within a scene, based upon their name... But with one object I'm sure about that there's only one (the edge of the scene, named 'Layer:Bak'), the &^%& avatars just walk through, without generating a collision event.... And sometimes they generate a collision event, where there are no objects... I'm at a loss... Any bright ideas about what I am doing wrong? I'm using Vizard R3 Beta 2 (maybe that helps) LINK TO IVE FILE Code:
import viz import random viz.go() # Set physicss viz.phys.enable() viz.phys.setGravity( 0, 0, 0 ) # Set start position viz.MainView.setPosition([20,2.7,20]) viz.clip(0.1,10000) viz.fov(70) viz.eyeheight(1.6) viz.stepsize(0.3) # add sky env = viz.add(viz.ENVIRONMENT_MAP,'temp0000.jpg') sky = viz.add('skydome.dlc') sky.texture(env) # disable headlight viz.disable(viz.LIGHT0) # add our light light=viz.addLight() light.position(0,20,0) light.intensity(1) light.ambient(.5,.5,.5) light.enable() # Set collision parameters for scene objects MallNames = ['Layer:Obstacle','Layer:Bak','Layer:VolBlokGevel','Layer:lm1','Layer:lm2','Layer:lm3','Layer:lm4','Layer:lm5','Layer:lm6','Layer:lm7','Layer:lm8','Layer:lm9','Layer:lm10'] MallObjects= [] for i in range(0,len(MallNames)): Bigobj = mall.getchild(MallNames[i]) Bigobj.collideMesh() Bigobj.disable(viz.DYNAMICS) MallObjects.append(Bigobj) #APPEND AND COLLIDEMESH OBJECTS FROM SCENE # place avatars avatars = [] #spawn = [[120,29,1],[60,67,1],[68,60,5],[109,70,5],[52,45,9],[105,21,9],[81,69,13],[92,13,13],[36,45,17],[91,38,17],[98,43,21],[71,85,21],[61,29,25],[61,74,25],[103,62,25],[112,91,25],[43,8,29],[76,63,29],[89,22,33],[74,85,33],[71,67,37],[117,36,37]] spawn = [[20,30,1]] # TEST LOCATION for i in range(0,10): #number of avatars mf = random.choice([0, 1]) # Random Male/Female location = random.choice(spawn) # Random pick spawn position rotation = random.choice([0,45,90,135,180,225,270,315]) #Random starting rotation avatarspeed = 0.5 + random.random() # random speed if mf==1: avatar = viz.add('male.cfg') else: avatar = viz.add('female.cfg') avatar.translate(location[0]+2*random.random()-1,location[2],location[1]+2*random.random()-1) #SPAWN avatar.rotate(0,1,0,rotation) #ROTATE avatar.speed(avatarspeed) # Set speed vector = avatar.get(viz.LOOK) # Get directional vector avatar.collideBox() #Physics avatar.disable(viz.DYNAMICS) #Physics avatar.enable(viz.COLLIDE_NOTIFY) #Physics avatar.addAction( vizact.walkto(location[0] + vector[0]*60,location[2],location[1] +vector[2]*60) ) #START WALKING avatars.append(avatar) #append avatar to array # Collision-routine def onCollide(e): if e.obj2 in avatars: print "avatar-avatar collision" if e.obj2 in MallObjects: print "avatar-object collision" e.obj1.endAction(pool=0) viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide ) Last edited by JvdBosch; 09-13-2006 at 07:31 AM. |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|