nlfrnassimi
03-15-2009, 09:13 PM
Hi again, I'm doing a project and I'll need a lot of help.
I want an object to move in y axis and define a hotspot for it, then have another object which moves in x axis and at a point (hotspot) they will meet and collide.
I've been able to make them collide but my hotspot starts when I use my mouse, I want when my first ball reaches the hotspot the second ball goes to that position and collide.
I've done some things but it doesn't seem professional.
Please help me
here is my code:
import viz
viz.go()
viz.clearcolor( viz.GRAY )
viz.phys.enable()
viz.phys.setGravity(0,0,0)
ground = viz.add('tut_ground.wrl')
ground.disable(viz.PHYSICS)
ball1 = viz.add( 'ball.wrl')
ball1StartPos = ball1.translate(0,0.2,9)
ball1.collideSphere()
ball2 = viz.add( 'ball.wrl' )
ball2StartPos = ball2.translate(4,0.2,9)
ball2.collideSphere()
BALL = 1
def onHotspot(id,x,y,z):
if id == BALL:
ball1.applyForce( dir = [ 0, 0, 1 ], duration=0.01, pos = ball2StartPos )
ball2.applyForce( dir = [ -1, 0, 0 ], duration=0.1, pos = ball1StartPos )
#def animation ():
#
# ball1.applyForce( dir = [ 0, 0, 1 ], duration=0.01, pos = ball2StartPos )
# ball2.applyForce( dir = [ -1, 0, 0 ], duration=0.1, pos = ball1StartPos )
#
#animation()
viz.callback(viz.HOTSPOT_EVENT,onHotspot)
#Attach a hotspot to the duck.
ball1.starthotspot(BALL, viz.CIRCLE_HOTSPOT_IN, 0,0,20)
viz.MainView.translate( 0, 2, -10 )
I want an object to move in y axis and define a hotspot for it, then have another object which moves in x axis and at a point (hotspot) they will meet and collide.
I've been able to make them collide but my hotspot starts when I use my mouse, I want when my first ball reaches the hotspot the second ball goes to that position and collide.
I've done some things but it doesn't seem professional.
Please help me
here is my code:
import viz
viz.go()
viz.clearcolor( viz.GRAY )
viz.phys.enable()
viz.phys.setGravity(0,0,0)
ground = viz.add('tut_ground.wrl')
ground.disable(viz.PHYSICS)
ball1 = viz.add( 'ball.wrl')
ball1StartPos = ball1.translate(0,0.2,9)
ball1.collideSphere()
ball2 = viz.add( 'ball.wrl' )
ball2StartPos = ball2.translate(4,0.2,9)
ball2.collideSphere()
BALL = 1
def onHotspot(id,x,y,z):
if id == BALL:
ball1.applyForce( dir = [ 0, 0, 1 ], duration=0.01, pos = ball2StartPos )
ball2.applyForce( dir = [ -1, 0, 0 ], duration=0.1, pos = ball1StartPos )
#def animation ():
#
# ball1.applyForce( dir = [ 0, 0, 1 ], duration=0.01, pos = ball2StartPos )
# ball2.applyForce( dir = [ -1, 0, 0 ], duration=0.1, pos = ball1StartPos )
#
#animation()
viz.callback(viz.HOTSPOT_EVENT,onHotspot)
#Attach a hotspot to the duck.
ball1.starthotspot(BALL, viz.CIRCLE_HOTSPOT_IN, 0,0,20)
viz.MainView.translate( 0, 2, -10 )