当前位置: 首页>>代码示例>>Python>>正文


Python BulletRigidBodyNode.setActive方法代码示例

本文整理汇总了Python中panda3d.bullet.BulletRigidBodyNode.setActive方法的典型用法代码示例。如果您正苦于以下问题:Python BulletRigidBodyNode.setActive方法的具体用法?Python BulletRigidBodyNode.setActive怎么用?Python BulletRigidBodyNode.setActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在panda3d.bullet.BulletRigidBodyNode的用法示例。


在下文中一共展示了BulletRigidBodyNode.setActive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CharacterController

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setActive [as 别名]
class CharacterController(DynamicObject, FSM):
	def __init__(self, game):
		self.game = game
		FSM.__init__(self, "Player")
		
		# key states
		# dx direction left or right, dy direction forward or backward
		self.kh = self.game.kh
		self.dx = 0
		self.dy = 0
		self.jumping = 0
		self.crouching = 0
		
		# maximum speed when only walking
		self.groundSpeed = 5.0
		
		# acceleration used when walking to rise to self.groundSpeed
		self.groundAccel = 100.0
		
		# maximum speed in the air (air friction)
		self.airSpeed = 30.0
		
		# player movement control when in the air
		self.airAccel = 10.0
		
		# horizontal speed on jump start
		self.jumpSpeed = 5.5
		
		self.turnSpeed = 5
		
		self.moveSpeedVec = Vec3(0,0,0)
		self.platformSpeedVec = Vec3(0,0,0)
		
		h = 1.75
		w = 0.4
		
		self.shape = BulletCapsuleShape(w, h - 2 * w, ZUp)
		self.node = BulletRigidBodyNode('Player')
		self.node.setMass(2)
		self.node.addShape(self.shape)
		self.node.setActive(True, True)
		self.node.setDeactivationEnabled(False, True)
		self.node.setFriction(200)
		#self.node.setGravity(10)
		#self.node.setFallSpeed(200)
		self.node.setCcdMotionThreshold(1e-7)
		self.node.setCcdSweptSphereRadius(0.5)
		self.node.setAngularFactor(Vec3(0,0,1))
		
		self.np = self.game.render.attachNewNode(self.node)
		self.np.setPos(0, 0, 0)
		self.np.setH(0)
		#self.np.setCollideMask(BitMask32.allOn())
		
		self.game.world.attachRigidBody(self.node)
		self.playerModel = None
		self.slice_able = False
		
	def setActor(self, modelPath, animDic={}, flip = False, pos = (0,0,0), scale = 1.0):
		self.playerModel = Actor(modelPath, animDic)
		self.playerModel.reparentTo(self.np)
		self.playerModel.setScale(scale) # 1ft = 0.3048m
		if flip:
			self.playerModel.setH(180)
		self.playerModel.setPos(pos)
		self.playerModel.setScale(scale)
	
	
	#-------------------------------------------------------------------
	# Speed	
	def getSpeedVec(self):
		return self.node.getLinearVelocity()
	def setSpeedVec(self, speedVec):
		#print "setting speed to %s" % (speedVec)
		self.node.setLinearVelocity(speedVec)
		return speedVec
		
	def setPlatformSpeed(self, speedVec):
		self.platformSpeedVec = speedVec
		
	def getSpeed(self):
		return self.getSpeedVec().length()
	def setSpeed(self, speed):
		speedVec = self.getSpeedVec()
		speedVec.normalize()
		self.setSpeedVec(speedVec*speed)
	
	def getLocalSpeedVec(self):
		return self.np.getRelativeVector(self.getSpeed())
	
	def getSpeedXY(self):
		vec = self.getSpeedVec()
		return Vec3(vec[0], vec[1], 0)
	def setSpeedXY(self, speedX, speedY):
		vec = self.getSpeedVec()
		z = self.getSpeedZ()
		self.setSpeedVec(Vec3(speedX, speedY, z))
	
	def getSpeedH(self):
		return self.getSpeedXY().length()
#.........这里部分代码省略.........
开发者ID:arikel,项目名称:PPARPG,代码行数:103,代码来源:characterController.py

示例2: BulletNPC

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setActive [as 别名]
class BulletNPC(DynamicObject):
    def __init__(self, name, game, pos):
        self.game = game
        self.name = name

        self.jumping = 0
        self.crouching = 0

        # maximum speed when only walking
        self.groundSpeed = 4.0

        # acceleration used when walking to rise to self.groundSpeed
        self.groundAccel = 150.0

        self.groundFriction = 0.0

        # maximum speed in the air (air friction)
        self.airSpeed = 30.0

        # player movement control when in the air
        self.airAccel = 10.0

        # horizontal speed on jump start
        self.jumpSpeed = 5.5

        self.turnSpeed = 5

        self.moveSpeedVec = Vec3(0, 0, 0)
        self.platformSpeedVec = Vec3(0, 0, 0)

        h = 1.75
        w = 0.4

        self.shape = BulletCapsuleShape(w, h - 2 * w, ZUp)
        self.node = BulletRigidBodyNode(self.name)
        self.node.setMass(1.0)
        self.node.addShape(self.shape)
        self.node.setActive(True, True)
        self.node.setDeactivationEnabled(False, True)
        self.node.setFriction(self.groundFriction)
        # self.node.setGravity(10)
        # self.node.setFallSpeed(200)
        self.node.setCcdMotionThreshold(1e-7)

        # do not use setCcdSweptSphereRadius
        # it messes up the bite contact test
        # self.node.setCcdSweptSphereRadius(0.5)

        self.node.setAngularFactor(Vec3(0, 0, 1))

        self.np = self.game.render.attachNewNode(self.node)
        self.setPos(pos)
        self.setH(0)
        # self.np.setCollideMask(BitMask32.allOn())

        self.game.world.attachRigidBody(self.node)
        self.playerModel = Actor(
            "models/monsters/ghoul2.egg",
            {"idle": "models/monsters/ghoul2-idle.egg", "walk": "models/monsters/ghoul2-walk.egg"},
        )
        self.playerModel.setScale(0.15)
        self.playerModel.setZ(0.15)
        self.playerModel.reparentTo(self.np)

        interval = Wait(random.uniform(0, 1))
        i2 = Func(self.startWalkAnim)
        seq = Sequence()
        seq.append(interval)
        seq.append(i2)
        seq.start()

        self.growlTimer = 5.0
        self.sound = None
        self.alive = True

        self.targetNp = NodePath(self.name)

        self.brainTimer = 0.0
        self.brainDelay = 1.2

        self.currentForce = Vec3(0, 0, 0)

    def startWalkAnim(self):
        self.playerModel.loop("walk")

    def stopWalkAnim(self):
        self.playerModel.loop("idle")

    def checkFront(self):
        p1 = Point3(self.getPos())
        direction = self.game.playerNp.getPos() - self.getPos()
        direction.normalize()
        direction = direction * 2.0
        p2 = Point3(self.getPos() + direction)

        result = self.game.world.rayTestClosest(p1, p2)

        # ts1 = TransformState.makePos(p1)
        # ts2 = TransformState.makePos(p2)
        # result = self.game.world.sweepTestClosest(self.shape, ts1, ts2, 0)
#.........这里部分代码省略.........
开发者ID:arikel,项目名称:PPARPG,代码行数:103,代码来源:bulletNPC.py


注:本文中的panda3d.bullet.BulletRigidBodyNode.setActive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。