PDA

View Full Version : physics


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 )

Jeff
03-16-2009, 10:59 AM
A hotspot is triggered when the viewpoint enters or leaves it. Here you have a hotspot that will be triggered when you enter it
ball1.starthotspot(BALL, viz.CIRCLE_HOTSPOT_IN, 0,0,20)
The radius of this circular hotspot is 20 meters so the viewpoint triggers it from the start.

It seems like a hotspot is not what you want here. Get the position of the first ball within a timer function and when it's at the position you want move the second ball towards it.

nlfrnassimi
03-16-2009, 10:32 PM
Thanks for your help, but what I want is something like proximity, instead of view entering a hotspot I want my object to enter that section and another action take place. Is there anything like proximity in vizard?

nlfrnassimi
03-18-2009, 08:47 PM
please help me with the above problem