コード例 #1
0
ファイル: step2.py プロジェクト: nikemr/PandaProject
#** Make the yolky roll on the the floor and jump
def avatarwalk(dt, vel):
    if vel[0]: avatar.setR(avatar.getR() + (40 * vel[0]))


#
def avatarjump(dt):
    if avatarFloorHandler.isOnGround():
        avatarFloorHandler.addVelocity(20)


#** Now we're ready to activate the avatar steering and go
steering = snipstuff.avatar_steer(avatarNP,
                                  avatarwalk,
                                  avatarjump,
                                  lefthand=False,
                                  steer2d=True)


def avatarup(move):
    global godmode
    if not godmode: move = 0
    return Vec3(0, 0, move)


def avatardown(move):
    global godmode
    if not godmode: move = 0
    return Vec3(0, 0, -move)
コード例 #2
0
ファイル: step8.py プロジェクト: kit-ipe/sensorsEditor
  showmessage()
acce('+', setdfc, [1])
acce('-', setdfc, [-1])

def setsfc(d):
  v=max(0.01, min(1.0, collisionHandler.getStaticFrictionCoef()+(.01*d)))
  collisionHandler.setStaticFrictionCoef(v)
  showmessage()
acce('*', setsfc, [1])
acce('/', setsfc, [-1])

#** Now we're ready to activate the avatar steering and go. Note how the jump routine changes in the physics environment: we add an 'impulse' as is a specific one-shot force - as in the real life works - and then it is the physics manager business to calculate the falling velocity and position during the simulation,
def avatarwalk(dt, vel):
  avatar=smiley.getChild(0).getChild(0)
  if vel[0]: avatar.setR(avatar.getR()+(40*vel[0]))
  if vel[1]: avatar.setP(avatar.getP()+(-38*vel[1]))
#
def avatarjump(dt):
  _smiley_actornode=smiley.getChild(0).node()
  if abs(_smiley_actornode.getPhysicsObject().getVelocity()[2]) < .01:
    _smiley_actornode.getPhysicsObject().addImpulse(Vec3(0,0,10))

steering=snipstuff.avatar_steer(
  smiley, avatarwalk, avatarjump, lefthand=False
)
steering.start()

#** let's start the show
splash.destroy()
run()
コード例 #3
0
ファイル: step4.py プロジェクト: nikemr/PandaProject
    snipstuff.infotext['message'].setText("Using single mesh collider")


normal_floor_collider()

snipstuff.DO.accept('1', normal_floor_collider)
snipstuff.DO.accept('2', oc3_floor_collider)


#** Make the smiley roll on the the floor...
def avatarwalk(dt, vel):
    if vel[0]: avatar.setR(avatar.getR() + (40 * vel[0]))
    if vel[1]: avatar.setP(avatar.getP() + (-38 * vel[1]))


#... and jump
def avatarjump(dt):
    if avatarFloorHandler.isOnGround():
        avatarFloorHandler.addVelocity(20)


#** Now we're ready to activate the avatar steering and go
steering = snipstuff.avatar_steer(avatarNP,
                                  avatarwalk,
                                  avatarjump,
                                  fwspeed=12.)
steering.start()

splash.destroy()
run()
コード例 #4
0
ファイル: step8.py プロジェクト: xwavex/pyhiro
    showmessage()


acce('*', setsfc, [1])
acce('/', setsfc, [-1])


#** Now we're ready to activate the avatar steering and go. Note how the jump routine changes in the physics environment: we add an 'impulse' as is a specific one-shot force - as in the real life works - and then it is the physics manager business to calculate the falling velocity and position during the simulation,
def avatarwalk(dt, vel):
    avatar = smiley.getChild(0).getChild(0)
    if vel[0]: avatar.setR(avatar.getR() + (40 * vel[0]))
    if vel[1]: avatar.setP(avatar.getP() + (-38 * vel[1]))


#
def avatarjump(dt):
    _smiley_actornode = smiley.getChild(0).node()
    if abs(_smiley_actornode.getPhysicsObject().getVelocity()[2]) < .01:
        _smiley_actornode.getPhysicsObject().addImpulse(Vec3(0, 0, 10))


steering = snipstuff.avatar_steer(smiley,
                                  avatarwalk,
                                  avatarjump,
                                  lefthand=False)
steering.start()

#** let's start the show
splash.destroy()
run()
コード例 #5
0

#** settling up the scene for the imminent show
frustum_toggle()
sentrotival.loop()
tsk1 = taskMgr.add(sent_detect, "sentdetect", priority=100)


#** Now we're ready to activate the avatar steering and go
def avatarwalk(dt, vel):
    if vel[0]: avatar.setR(avatar.getR() + (40 * vel[0]))
    if vel[1]: avatar.setP(avatar.getP() + (-38 * vel[1]))


#
def avatarjump(dt):
    if avatarFloorHandler.isOnGround(): avatarFloorHandler.addVelocity(20)


#
steering = snipstuff.avatar_steer(avatarNP,
                                  avatarwalk,
                                  avatarjump,
                                  fwspeed=8.,
                                  lefthand=False)
steering.start()

#** let's start the show
splash.destroy()
run()
コード例 #6
0
ファイル: step1.py プロジェクト: nikemr/PandaProject
avatarRay = avatar.attachNewNode(CollisionNode('avatarRay'))
avatarRay.node().addSolid(raygeometry)
# this is how we tell the collision system that this ray would collide just with the floor acting as a FROM collider.
avatarRay.node().setFromCollideMask(FLOOR_MASK)
# we then exclude the ray from acting as an INTO collider
avatarRay.node().setIntoCollideMask(BitMask32.allOff())

#** This is the terrain - the egg model we load contains also the collider geometry as child
terrain = loader.loadModel("scene1")
terrain.reparentTo(render)
terrain.setCollideMask(BitMask32.allOff())
terrain.setScale(10)
# here how we tell the collision system that the terrain collider geometry is allowed to collide with the avatar ray as INTO collider
floorcollider = terrain.find("**/floor_collide")
floorcollider.node().setIntoCollideMask(FLOOR_MASK)

#** We set here the collison handler to use our avatar ray as into collider to detect the contact point along the Z axis and also which is the avatar nodepath to take control - this means to say that while we steer horizontally our avatar, changing its X and Y position from here to there, the handler will take care to set its Z position automatically, eventually simulating when falling down if we drop the avatar in middle air.
floorHandler.addCollider(avatarRay, avatar)
# the following setup will shift the floor contact hit position detection a little up. This is cause the CollisionHandlerFloor uses the avatar origin as reference to drive it and don't care to detect when it touch the floor surface with its  outer geometry. It's up to you to settle things to keep the avatar staying up the floor relative to the avatar's origin. Note though that this is not the recommended way to proceed in real applications, cause if we got different models with different shapes and origins roaming around, we'd see them not touching the floor correctly but or half-submerged into the terrain or not toching it at all, looking floating into the air. The correct way to go will be to interpose another nodepath to the avatar, shifting off this one instead. We'll see this better in step2.py snippet.
floorHandler.setOffset(1.0)

#** Now we're ready to start the collisions using the floorHandler and the ray to fire collisions
base.cTrav.addCollider(avatarRay, floorHandler)

#** Activating avatar steering function - now we're ready to go
steering = snipstuff.avatar_steer(avatar)
steering.start()

splash.destroy()
run()
コード例 #7
0
floorcollider.node().setIntoCollideMask(FLOOR_MASK)
#...and the same goes for the walls
wallcollider = terrain.find("**/wall_collide")
wallcollider.node().setIntoCollideMask(WALL_MASK)

#** as said in step1 we tells to our collision handlers who take part to the respective tasks: for the floor the avatar ray and the avatar nodepath...
floorHandler.addCollider(avatarRay, avatarNP)
# ...and for the walls the avatar sphere collider together with - again - the avatar nodepath
wallHandler.addCollider(avatarCollider, avatarNP)

wallHandler.addCollider(artCollider, avatarNP)
wallHandler.addCollider(avatar2Collider, avatarNP)
wallHandler.addCollider(art2Collider, avatarNP)

#** Now we're ready to start the collisions using the avatar ray to use to fire collisions for the floorHandler...
base.cTrav.addCollider(avatarRay, floorHandler)
# ... and the sphere for the wallHandler
base.cTrav.addCollider(avatarCollider, wallHandler)

base.cTrav.addCollider(artCollider, wallHandler)
base.cTrav.addCollider(avatar2Collider, wallHandler)
base.cTrav.addCollider(art2Collider, wallHandler)

# A task to run every frame, some keyboard setup and our speed
taskMgr.add(updateTask, "update")
#** Activating avatar steering function - now we're ready to go
steering = snipstuff.avatar_steer(avatarNP, fwspeed=12.)
steering.start()
splash.destroy()
base.run()