PDA

View Full Version : Help Creating Interactive City Env from .dae


vJimZ
09-14-2010, 12:07 AM
Hi everyone,

I'm fairly new to Vizard, and am having trouble making the environment map of a city interactive.

The environment map is loaded from a .dae file, and contains the ground floor as well as a sea layer above it, and some buildings.

I have an avatar moving around the world, controlled by arrow keys.

I would like to make it so that the user cannot collide with either the buildings and the sea areas.
I tried collisionMesh, collisionBox, and collisionSphere on both the avatar and the environ map variable and they do not work; the avatar simply walks through them. When I try a simple line like printing "collide" on collision, nothing happens.

My code is:
--------------------------------------------------------------------------
import necessary files

viz.go()
viz.clearcolor(viz.SKYBLUE)
viz.phys.enable()

#Resources

#Builds the basic background resources
city = viz.add('art/city.dae')
city.setScale([.01,.01,.01])
city.collideMesh()
viz.collision(viz.ON)
viz.collisionbuffer(0.3)

#######Add avatar details here###############
male = viz.add('vcc_male.cfg')
male.setPosition([10.0, 0, 40.0])
male.collideMesh()

### Sets the position to be just behind the avatar
matrixPos = male.getPosition()
matrixPos[2] = matrixPos[2] - 10
viz.MainView.setPosition(matrixPos)

## other functions here that account for movement####
#######################################

Jeff
09-14-2010, 01:45 PM
It's possible if the models are too thin the physics engine will not register the collision.

What code did you use to be notified of a collision and print that it occured?

vJimZ
09-14-2010, 04:30 PM
Hi Jeff,

Thanks for the reply.

To make the code detect a collision:
male.enable(viz.COLLIDE_NOTIFY)
def onCollide(e):
print "collided"

viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide)

The console prints "collided" when the character first lands, and plenty of "collided" are printed as the character is running around, but not when buildings are hit. The world is around 30km x 30km x 10km, but I scaled it by a factor of 0.01.

Is there some way to increase the "thickness" of the model to the point that it can detect collisions?

Gladsomebeast
09-15-2010, 11:23 AM
Because viz.COLLIDE_BEGIN_EVENT only calls onCollide once per collision, you get one notification of collision when the avatar hits the city model's ground, even though the avatar moves on to collide with the city model's buildings.

so events go like this: avatar drops into world -> collide begin event called -> avatar is still colliding with world but walking around -> avatar walks into building but never lost touch with city model so no new collide begin event.

I think the better way to move you avatar around in the world is with a velocity motor created with the male.addVelocity fuction. There are a few tricks on how to use a velocity motor, so check out the docs on "addVelocity" and the example script in this article:

http://vizworkshop.com/articles/walkthrough_app