WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-16-2013, 06:11 PM
Daithi90 Daithi90 is offline
Member
 
Join Date: Jan 2013
Posts: 3
Can I apply a force on an object by running into it?

I'm trying to create a stack of barrels that will fall apart when the user bumps into them. As is, nothing happens but if i apply force to another object in the barrels' direction they do fall.

I get the feeling it's only something small but as I'm relatively new to Vizard, I'm not too sure.
Reply With Quote
  #2  
Old 03-15-2013, 09:42 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Yes, you could try placing a collision shape at the viewpoint location to detect the collision. Then in the collision callback, add a force to the object that was collided with:
Code:
import viz
import vizact
viz.go()

viz.MainView.move([0,-0.8,0])

viz.phys.enable()

ground = viz.add('ground.osgb')
ground.collidePlane()

#Add crates to collide with
crate1 = viz.addChild('crate.osgb',pos=[0.7,0.3,5],scale=[0.6,0.6,0.6])
crate2 = crate1.clone(pos=[0,0.3,5.1],euler=[5,0,0],scale=[0.6,0.6,0.6])
crate3 = crate1.clone(pos=[0.3,0.9,5.1],euler=[-5,0,0],scale=[0.6,0.6,0.6])

crate1.collideBox()
crate2.collideBox()
crate3.collideBox()

crates = [crate1,crate2,crate3]

#Add an invisible cube to detect collisions with the crates
import vizshape
cube = vizshape.addCube(size=0.3)
cube.collideBox()
cube.enable(viz.COLLIDE_NOTIFY)
cube.disable(viz.RENDERING)
cube.disable(viz.DYNAMICS)

#Place the cube at the viewpoint location
def updateCube():
	cube.setPosition(viz.MainView.getPosition())
	cube.setQuat(viz.MainView.getQuat())
	
vizact.onupdate(0,updateCube)

#Apply a force to the crate when the viewpoint
#and invisible cube collides with it
def onCollideBegin(e):
	if e.obj1 == cube and e.obj2 in crates:
		dir = viz.MainView.getMatrix().getForward()
		e.obj2.applyForce(dir,duration=0.1)

viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegin)
Reply With Quote
Reply

Tags
4.0, collision, forces, physics

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
How to render a texture of the transparent object and then blur it whj Vizard 1 09-25-2012 04:15 PM
how to apply two textures to one 3D object? sqwiggily Vizard 3 03-15-2012 08:39 PM
How to apply shader and render texture to an object whj Vizard 0 04-23-2010 01:23 PM
retrieve Object names Geoffrey Vizard 11 12-11-2009 05:26 AM
rotate to object jargon Vizard 1 08-08-2005 01:20 PM


All times are GMT -7. The time now is 10:57 AM.


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