) snipstuff.info.append("WASD=move the avatar around\nSPACE=avatar hiccup") snipstuff.info_show() #========================================================================= # Main """ Starting from step1, we just put an additional collision handler to take care to keep the avatar grounded. This will PUSH the avatar back as soon as hit geometry we settled to be a wall: in blender we modelled polygons to wrap around the little house and all around the terrain area so that this time the avatar, differently from step1, won't pass through the house and won't be able to leave the terrain perimeter anymore. I suggest you to open the blender source to find out what I'm talking about here. """ #========================================================================= #** Collision system ignition base.cTrav = CollisionTraverser() # did you saw this stuff in step1? floorHandler = CollisionHandlerFloor() floorHandler.setMaxVelocity(14) # here it is the new fella - this will take care to push the avatar off the walls wallHandler = CollisionHandlerPusher() #** As you know this mask is used to mark the geometries for the floor collisions... FLOOR_MASK = BitMask32.bit(1) #... and this time we need another one to mark the walls as well. WALL_MASK = BitMask32.bit(2) #** This is our steering avatar - this time we use a little different setup, more close to real applications: we wrap either the avatar and its collision ray into another nodepath. This way we add lotta flexibility allowing us to make fancy things like you'll see below, to make the avatar rolling while steering, a thing not possible before and also to get rid of the global floorHandler.setOffset(1.0) shift, to set our avatar precisly placed above the surface. avatarNP = NodePath('smileyNP') avatarNP.reparentTo(base.render) avatar = loader.loadModel('smiley') avatar.reparentTo(avatarNP) # since our avatar origin is centered in a model sized 2,2,2, we need to shift it 1 unit above the ground and this time we make this happen shifting it off its own root node (avatarNP) avatar.setPos(0, 0, 1)
from direct.showbase.DirectObject import DirectObject from pandac.PandaModules import CollisionHandlerEvent, CollisionHandlerQueue, CollisionHandlerFloor, CollisionHandlerPusher, CollisionNode, CollisionTube, CollisionSphere, CollisionRay, CollisionTraverser, BitMask32 from doomsday.base import Globals, SoundBank from doomsday.world.Splat import Splat from panda3d.core import Vec4, Vec3 import math collHdl = CollisionHandlerEvent() collHdlF = CollisionHandlerFloor() collHdlF.setMaxVelocity(8) collHdlPush = CollisionHandlerPusher() class WorldCollisions(DirectObject): def __init__(self): base.cTrav = CollisionTraverser() self.called = False def handleInCollisions(self, entry): cogCollNames = ['coll_body', 'coll_crit'] intoNode = entry.getIntoNodePath() fromNode = entry.getFromNodePath() if(self.called): return self.called = True splatColor = Vec4(0.7, 0.7, 0.8, 1.0) splatScale = 0.7 if(intoNode.getName() in cogCollNames): cog = intoNode.getParent().getPythonTag('Cog') gag = fromNode.getParent().getPythonTag('Stats') splatColor = gag.getSplatColor()
from direct.showbase.DirectObject import DirectObject from pandac.PandaModules import CollisionHandlerEvent, CollisionHandlerQueue, CollisionHandlerFloor, CollisionHandlerPusher, CollisionNode, CollisionTube, CollisionSphere, CollisionRay, CollisionTraverser, BitMask32 from doomsday.base import Globals, SoundBank from doomsday.world.Splat import Splat from panda3d.core import Vec4, Vec3 import math collHdl = CollisionHandlerEvent() collHdlF = CollisionHandlerFloor() collHdlF.setMaxVelocity(8) collHdlPush = CollisionHandlerPusher() class WorldCollisions(DirectObject): def __init__(self): base.cTrav = CollisionTraverser() self.called = False def handleInCollisions(self, entry): cogCollNames = ['coll_body', 'coll_crit'] intoNode = entry.getIntoNodePath() fromNode = entry.getFromNodePath() if (self.called): return self.called = True splatColor = Vec4(0.7, 0.7, 0.8, 1.0) splatScale = 0.7 if (intoNode.getName() in cogCollNames): cog = intoNode.getParent().getPythonTag('Cog') gag = fromNode.getParent().getPythonTag('Stats') splatColor = gag.getSplatColor()