本文整理汇总了Python中panda3d.bullet.BulletWorld.attachCharacter方法的典型用法代码示例。如果您正苦于以下问题:Python BulletWorld.attachCharacter方法的具体用法?Python BulletWorld.attachCharacter怎么用?Python BulletWorld.attachCharacter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletWorld
的用法示例。
在下文中一共展示了BulletWorld.attachCharacter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachCharacter [as 别名]
#.........这里部分代码省略.........
self.debugNP.hide()
def doScreenshot(self):
base.screenshot("Bullet")
# def doJump(self):
# self.player.setMaxJumpHeight(5.0)
# self.player.setJumpSpeed(8.0)
# self.player.doJump()
# def doCrouch(self):
# self.crouching = not self.crouching
# sz = self.crouching and 0.6 or 1.0
# self.playerNP2.setScale(Vec3(1, 1, sz))
# ____TASK___
def processInput(self, dt):
speed = Vec3(0, 0, 0)
omega = 0.0
if inputState.isSet("forward"):
speed.setY(2.0)
if inputState.isSet("reverse"):
speed.setY(-2.0)
if inputState.isSet("left"):
speed.setX(-2.0)
if inputState.isSet("right"):
speed.setX(2.0)
if inputState.isSet("turnLeft"):
omega = 120.0
if inputState.isSet("turnRight"):
omega = -120.0
self.player.setAngularMovement(omega)
self.player.setLinearMovement(speed, True)
def update(self, task):
dt = globalClock.getDt()
self.processInput(dt)
self.world.doPhysics(dt, 4, 1.0 / 240.0)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
def setup(self):
self.worldNP = render.attachNewNode("World")
# World
self.debugNP = self.worldNP.attachNewNode(BulletDebugNode("Debug"))
self.debugNP.show()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Ground
shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
# img = PNMImage(Filename('models/elevation2.png'))
# shape = BulletHeightfieldShape(img, 1.0, ZUp)
np = self.worldNP.attachNewNode(BulletRigidBodyNode("Ground"))
np.node().addShape(shape)
np.setPos(0, 0, -1)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
# Box
shape = BulletBoxShape(Vec3(1.0, 3.0, 0.3))
np = self.worldNP.attachNewNode(BulletRigidBodyNode("Box"))
np.node().setMass(50.0)
np.node().addShape(shape)
np.setPos(3, 0, 4)
np.setH(0)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
# Character
h = 1.75
w = 0.4
shape = BulletCapsuleShape(w, h - 2 * w, ZUp)
self.player = BulletCharacterNode(shape, 0.4, "Player")
self.player.setMass(20.0)
self.player.setMaxSlope(45.0)
self.player.setGravity(9.81)
self.playerNP = self.worldNP.attachNewNode(self.player)
self.playerNP.setPos(-2, 0, 10)
self.playerNP.setH(-90)
self.playerNP.setCollideMask(BitMask32.allOn())
self.world.attachCharacter(self.player)
示例2: FriendlyFruit
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachCharacter [as 别名]
class FriendlyFruit(ShowBase, Scene):
def __init__(self, server_connection, player_tag):
ShowBase.__init__(self)
self.__server_connection = server_connection
self.__player_tag = player_tag
self.__rotations = {}
# Panda pollutes the global namespace. Some of the extra globals can be referred to in nicer ways
# (for example self.render instead of render). The globalClock object, though, is only a global! We
# create a reference to it here, in a way that won't upset PyFlakes.
self.globalClock = __builtins__["globalClock"]
# Turn off the debugging system which allows the camera to be adjusted directly by the mouse.
self.disableMouse()
# Set up physics: the ground plane and the capsule which represents the player.
self.world = BulletWorld()
# The ground first:
shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
node = BulletRigidBodyNode("Ground")
node.addShape(shape)
np = self.render.attachNewNode(node)
np.setPos(0, 0, 0)
self.world.attachRigidBody(node)
# Enable shader generation (for more sophisticated lighting etc.)
self.render.setShaderAuto()
# Create lights so we can see the scene.
dlight = DirectionalLight("dlight")
dlight.setColor(VBase4(2, 2, 2, 0))
dlnp = self.render.attachNewNode(dlight)
dlnp.setHpr(0, -60, 0)
self.render.setLight(dlnp)
alight = AmbientLight('alight')
alight.setColor(VBase4(0.75, 0.75, 0.75, 0))
alnp = self.render.attachNewNode(alight)
self.render.setLight(alnp)
# Create a task to update the scene regularly.
self.taskMgr.add(self.update, "UpdateTask")
# Update the scene by turning objects if necessary, and processing physics.
def update(self, task):
asyncore.loop(timeout=0.01, use_poll=True, count=1)
for node, angular_velocity in self.__rotations.iteritems():
node.setAngularMovement(angular_velocity)
dt = self.globalClock.getDt()
self.world.doPhysics(dt)
return task.cont
def server_created_object(self, tag, height, radius):
# This shape is used for collision detection, preventing the player falling through the ground for
# example.
shape = BulletCapsuleShape(radius, height - 2 * radius, ZUp)
# A character controller is a physical body which responds instantly to keyboard controls. (Bodies
# which respond to forces are difficult to control in a satisfactory way using typical video game
# controls. Players expect them to move instantly when a button is pressed, but physics dictates that
# they should take a short time to accelerate.)
node = BulletCharacterControllerNode(shape, 0.4, tag)
node_path = self.render.attachNewNode(node)
Thing.add(tag, node, node_path)
self.world.attachCharacter(node)
# Does this object represent the player who is using this client?
if tag == self.__player_tag:
# If yes, attach the camera to the object, so the player's view follows the object.
self.camera.reparentTo(node_path)
else:
# If no, create a new Actor to represent the player or NPC.
humanoid = Actor("player.bam")
humanoid.setH(180)
humanoid.reparentTo(node_path)
# Scale the Actor so it is the same height as the bounding volume requested by the server.
point1 = Point3()
point2 = Point3()
humanoid.calcTightBounds(point1, point2)
humanoid.setScale(height / (point2.z - point1.z))
# If the 3D model has the origin point at floor level, we need to move it down by half the height
# of the bounding volume. Otherwise it will hang in mid air, with its feet in the middle of the
# bounding volume.
humanoid.setZ(-height / 2)
def server_removed_object(self, tag):
thing = Thing.get_thing(tag)
self.world.removeCharacter(thing.node)
thing.node_path.removeNode()
thing.remove()
def server_moves_thing(self, tag, loc_x, loc_y, loc_z, speed_x, speed_y, speed_z, angle, angular_velocity):
thing = Thing.get_thing(tag)
thing.node_path.setPos(loc_x, loc_y, loc_z)
thing.node.setLinearMovement(Vec3(speed_x, speed_y, speed_z), True)
#.........这里部分代码省略.........
示例3: BulletEngine
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachCharacter [as 别名]
#.........这里部分代码省略.........
##测试碰撞平面(南)
normal = Vec3(-1,0,0)
d = 0
shape = BulletPlaneShape(normal,d)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('north_end'))
np.node().addShape(shape)
np.setPos(330,0,0)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
# Some boxes
# size = 9.0
# shape = BulletBoxShape(Vec3(size,size,size))
# body = BulletRigidBodyNode('Big box')
# self.boxNP = self.worldNP.attachNewNode(body)
# self.boxNP.node().addShape(shape)
# # self.boxNP.node().setMass(100.0)
# self.boxNP.node().setDeactivationEnabled(False)
# self.boxNP.setPos(0,0,10)
# self.boxNP.setCollideMask(BitMask32.allOn())
# self.world.attachRigidBody(self.boxNP.node())
house1NP = self.create_box_rigid('house1',Vec3(5,5,5),Vec3(0,0,5),False)
self.world.attachRigidBody(house1NP.node())
house1NP.node().setDeactivationEnabled(False)
# 猎人
actor = self.sceneMgr.add_actor_scene(HUNTER_PATH,
HUNTER_ACTION_PATH,
self.render)
actor.setPos(0,1,-10)
actor.setScale(1.6)
actor.setTwoSided(True)
self.add_actor_collide(actor,3.5,15)
# control
self.sceneMgr.get_ActorMgr().set_clock(globalClock)
actorId = self.sceneMgr.get_ActorMgr().get_resId(actor)
self.sceneMgr.get_ActorMgr().add_toggle_to_actor("w", actorId, "run")
self.sceneMgr.get_ActorMgr().add_toggle_to_actor("s", actorId, "run_back")
self.sceneMgr.get_ActorMgr().add_toggle_to_actor("z", actorId, "rda")
self.sceneMgr.get_ActorMgr().add_toggle_to_actor("x", actorId, "lda")
self.sceneMgr.get_ActorMgr().add_toggle_to_actor("c", actorId, "bda")
print "actorId : ", actorId
camCtrlr = CameraController()
camCtrlr.bind_camera(self.cam)
camCtrlr.bind_ToggleHost(self)
camCtrlr.set_clock(globalClock)
camCtrlr.focus_on(actor, 100)
camCtrlr.set_rotateSpeed(10)
camCtrlr.add_toggle_to_opt("u", "rotate_around_up")
camCtrlr.add_toggle_to_opt("j", "rotate_around_down")
camCtrlr.add_toggle_to_opt("h", "rotate_around_cw")
camCtrlr.add_toggle_to_opt("k", "rotate_around_ccw")
self.sceneMgr.bind_CameraController(camCtrlr)
self.sceneMgr.get_ActorMgr().bind_CameraController(camCtrlr)
print self.sceneMgr.get_ActorMgr().get_eventActionRecord()
print self.sceneMgr.get_ActorMgr().get_eventEffertRecord()
self.roleMgr = RoleManager()
self.sceneMgr.get_ActorMgr().bind_RoleManager(self.roleMgr)
self.roleMgr.bind_SceneManager(self.sceneMgr)
player = self.roleMgr.create_role(roleType="PlayerRole",
modelId=actorId)
player.print_all_attr()
self.taskMgr.add(self.sceneMgr.update_scene, "update_scene")
def add_actor_collide(self,actor,radius,height):
# 猎人胶囊碰撞体
r = radius
h = height
self.actor_shape = BulletCapsuleShape(r, height, ZUp)
self.actor_character_NP = BulletCharacterControllerNode(self.actor_shape, 1.0, 'Player')
self.actorNP = self.worldNP.attachNewNode(self.actor_character_NP)
self.actorNP.setPos(-20, 30, 0)
self.actorNP.setCollideMask(BitMask32.allOn())
self.world.attachCharacter(self.actorNP.node())
# actor.detachNode(self.world)
actor.reparentTo(self.actorNP)
def add_house_collide(self, house, size,pos,houseName):
# geomNodes = loader.loadModel(TEST_HOUSE1).findAllMatches('**/+GeomNode')
# geomNode = geomNodes.getPath(0).node()
# geom = geomNode.getGeom(0)
# house_shape = BulletConvexHullShape()
# house_shape.addGeom(geom)
# houseNP = self.worldNP.attachNewNode(BulletRigidBodyNode(houseName))
# houseNP.node().addShape(house_shape)
# houseNP.setPos(pos)
# # houseNP.node().setMass(10.0)
# houseNP.setCollideMask(BitMask32.allOn())
# self.world.attachRigidBody(houseNP.node())
# house.reparentTo(houseNP)
# house.setPos(0,0,0)
pass
示例4: EccoGame
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachCharacter [as 别名]
#.........这里部分代码省略.........
self.gameOverSound = base.loader.loadSfx("sounds/Bike Horn-SoundBible.com-602544869.wav")
self.levelCompleteSound = base.loader.loadSfx("sounds/Ta Da-SoundBible.com-1884170640.wav")
def setupFloor(self):
size = Vec3(7.5, 3000, 1.81818)
shape = BulletBoxShape(size * 0.55)
# shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
node = BulletRigidBodyNode('Box-Floor')
node.addShape(shape)
node.setMass(0)
stairNP = self.render.attachNewNode(node)
stairNP.setPos(0, 0, 0)
stairNP.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(stairNP.node())
modelNP = loader.loadModel('models/box.egg')
modelNP.reparentTo(stairNP)
modelNP.setPos(-size.x / 2.0, -size.y / 2.0, -size.z / 2.0)
modelNP.setScale(size)
def setupCharacter(self):
# Character
h = 1.75
w = 0.4
shape = BulletCapsuleShape(w, h - 2 * w, ZUp)
self.character = BulletCharacterControllerNode(shape, 0.4, 'Player')
self.character.setGravity(35)
self.characterNP = self.render.attachNewNode(self.character)
self.characterNP.setPos(0, 10, 5)
self.characterNP.setCollideMask(BitMask32.allOn())
self.world.attachCharacter(self.character)
self.ecco = Actor('ralph-models/ralph.egg.pz', {
'run': 'ralph-models/ralph-run.egg',
'jump': 'ralph/ralph-run.egg',
'damage': 'models/lack-damage.egg'})
self.ecco.reparentTo(self.characterNP)
self.ecco.setScale(0.7048)
self.ecco.setH(180)
def setUpCamera(self):
# If the camera is too far from ecco, move it closer.
# If the camera is too close to ecco, move it farther.
camvec = self.characterNP.getPos() - self.camera.getPos()
camvec.setZ(0.0)
camdist = camvec.length()
camvec.normalize()
if camdist > 10.0:
self.camera.setPos(self.camera.getPos() + camvec * (camdist - 40))
camdist = 10.0
if camdist < 5.0:
self.camera.setPos(self.camera.getPos() - camvec * (35 - camdist))
camdist = 5.0
def processInput(self, dt):
speed = Vec3(0, 0, 0)
if inputState.isSet('esc'): sys.exit()
if inputState.isSet('w'): speed.setY(35.0)
if inputState.isSet('arrow_left'): speed.setX(-35.0)
if inputState.isSet('arrow_right'): speed.setX(35.0)
if inputState.isSet('space'):
self.jump()
self.jumpSound.play()