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


Python BulletRigidBodyNode.setLinearVelocity方法代码示例

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


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

示例1: Shoot

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setLinearVelocity [as 别名]
class Shoot( ) :
    
    def __init__(self, showbase) :
        
        self.showbase = showbase
        self.actor = showbase.actor
        
        print('Press "q" to shoot')
        showbase.accept('q', self.createBall)

    def createBall(self) :
        
        self.actor.play("launch")

        # Sphere
        self.shape = BulletSphereShape(0.15)
        self.node = BulletRigidBodyNode('Sphere')
        self.node.setMass(1)
        self.node.addShape(self.shape)
        self.np = self.showbase.render.attachNewNode(self.node)
        self.np.setPos(self.actor.getX(), self.actor.getY(), self.actor.getZ() + 2.5)

        # Smiley
        self.model = self.showbase.loader.loadModel("./models/smiley")
        self.model.setTexture(self.showbase.loader.loadTexture(imagePath + 'metal1.jpg'), 1)
        self.model.flattenLight()
        self.model.setScale(0.15, 0.15, 0.15)
        self.model.reparentTo(self.np)
        
        # Set speed
        h = self.actor.getH()
        if(h == 0) :
            x = 0
            y = 8
        if(h == 90) :
            x = -7
            y = 0
        if(h == 180) :
            x = 0
            y = -8
        if(h == -90) :
            x = 8
            y = 0
            
        self.node.setLinearVelocity(Vec3(x, y, 6.2)) #self.actor.getX()/3, 11, 6.2)
        self.showbase.world.attachRigidBody(self.node)
开发者ID:trinobster,项目名称:MiniGame,代码行数:48,代码来源:Shoot.py

示例2: Flame

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setLinearVelocity [as 别名]
class Flame(Entity):
    """
    The thing that comes out the end of the thing you hold
    """
    animspeed = 0.1 
    depth = 20 
    playerWidth = 3
    speed = 20 

    def __init__(self, world, pos, hpr):
        super(Flame, self).__init__()

        self.shape = BulletBoxShape(Vec3(0.1,0.05,0.05))
        self.bnode = BulletRigidBodyNode()
        self.bnode.setMass(1.0)
        self.bnode.addShape(self.shape)

        self.np = utilities.app.render.attachNewNode(self.bnode)

        self.world =world 
        self.anim = list()
        self.anim.append(utilities.loadObject("flame1", depth=0))
        self.anim.append(utilities.loadObject("flame2", depth=0))
        self.anim.append(utilities.loadObject("flame3", depth=0))
        world.bw.attachRigidBody(self.bnode)

        self.curspr = 0
        self.obj = self.anim[self.curspr]
        self.obj.show() 
        self.livetime = 0
        self.delta = 0

        self.pos = pos
        self.pos.y = Flame.depth
        #self.pos.z -= 0.2 
        self.hpr = hpr
        self.vel = Point2()
        self.vel.x = cos(world.player.angle)*Flame.speed
        self.vel.y = sin(world.player.angle)*Flame.speed

        tv = Vec3(self.vel.x, 0, self.vel.y)
        # this makes the shot miss the target if the player has any velocity
        tv += world.player.bnode.getLinearVelocity()

        self.bnode.setLinearVelocity(tv)

        tv.normalize()

        # initial position of RB and draw plane
        self.np.setHpr(hpr)
        self.np.setPos(pos+tv/2)

        self.bnode.setAngularFactor(Vec3(0,0,0))
        self.bnode.setLinearFactor(Vec3(1,0,1))
        self.bnode.setGravity(Vec3(0,0,0))

        self.bnode.setCcdMotionThreshold(1e-7)
        self.bnode.setCcdSweptSphereRadius(0.10)

        self.bnode.notifyCollisions(True)
        self.bnode.setIntoCollideMask(BitMask32.bit(1))
        self.bnode.setPythonTag("Entity", self)
        self.noCollideFrames = 4

        for a in self.anim:
            a.hide()
            a.reparentTo(self.np)
            a.setScale(0.25, 1, 0.25)
            a.setPos(0, -0.1,0)

    def update(self, timer):
        #animation
        self.delta += timer
        self.livetime += timer

        if self.noCollideFrames == 0:
            self.bnode.setIntoCollideMask(BitMask32.allOn())

        if self.noCollideFrames > -1:
            self.noCollideFrames -= 1


        if self.delta > Flame.animspeed:
            self.delta = 0
            self.obj.hide()
            self.curspr += 1
        if self.curspr > len(self.anim)-1:
            self.curspr = 0
            self.obj = self.anim[self.curspr]
            self.obj.show()
开发者ID:fcostin,项目名称:gravbot,代码行数:92,代码来源:items.py

示例3: Chunk

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setLinearVelocity [as 别名]
class Chunk(Entity):
    chunkmass = 5.0
    def __init__(self, world, blocks, pos, hpr=Point3(0,0,0), diff = Vec3(0,0,0), angVel = Vec3(0,0,0), linVel = Vec3(0,0,0)):
        super(Chunk, self).__init__()

        self.mass = len(blocks)*Chunk.chunkmass
        self.world = world
        self.blocks = blocks

        self.bnode = BulletRigidBodyNode()

        self.bnode.setMass(self.mass)
        self.bnode.setAngularFactor(Vec3(0,1,0))
        self.bnode.setLinearSleepThreshold(20)
        self.bnode.setAngularSleepThreshold(20)
        self.bnode.setAngularVelocity(angVel)

        self.bnode.setLinearVelocity(linVel)
        self.np = utilities.app.render.attachNewNode(self.bnode)
        self.np.setPos(pos.x,20,pos.y)
        self.np.setHpr(hpr)
        self.np.setPos(self.np, diff)
    
        self.bnode.setPythonTag("entity", self)

        self.inScope = False # culling not done yet

        # centre the blocks around the np and add their shapes in.
        self.minMax()
        cog = Point2((self.minX+self.maxX) / 2.0, (self.minY+self.maxY) / 2.0)
        for block in blocks:
            block.rebuild(self, cog)

        world.bw.attachRigidBody(self.bnode)
        self.hitlist = dict()

    def update(self, timer):
        for index in self.hitlist:
            # returns true if the wall is destroyed by the hit
            if self.blocks[index].hitby(self.hitlist[index]):
                self.blocks[index].destroy()
                self.rebuild(index)
        self.hitlist.clear()    

        if self.playerDistance() > 40.0:
            self.bnode.setAngularSleepThreshold(1)
            self.bnode.setLinearSleepThreshold(1)
        else:    
            self.bnode.setAngularSleepThreshold(0)
            self.bnode.setLinearSleepThreshold(0)
    

    def playerDistance(self):
        sp = self.np.getPos()
        pp = self.world.player.node.getPos()

        distance = hypot(sp.x - pp.x, sp.z - pp.z)
        return distance
        
    # remove an element and rebuild
    # TODO add another method for removing multiple
    # blocks in a single go
    def rebuild(self, index):
        deadblock = self.blocks[index]
        out = list()

        for block in self.blocks:
            for edge in block.edges:
                if edge == deadblock:
                    block.edges.remove(edge)

        for block in deadblock.edges:
            chunk = list()
            self.searchBlock(block, chunk, deadblock)
            out.append(chunk)

        #out is a list of lists of populated blocks
        #remove duplicate chunks
        results = list()
        for chunk in out:
            chunk.sort(compareBlock)
            if not chunk in results and len(chunk) > 0:
                results.append(chunk)
    
        for result in results:
            self.minMax(result)
            #diff = Point2((self.minX+self.maxX) / 2.0, (self.minY+self.maxY) / 2.0)
            diff = Vec3((self.minX+self.maxX) / 2.0, 0, (self.minY+self.maxY) / 2.0)
            p = self.np.getPos()
            pos = Point2(p.x, p.z)
            h = self.np.getHpr()
            self.world.entities.append(Chunk(self.world, result, pos, h, diff, self.bnode.getAngularVelocity(), self.bnode.getLinearVelocity()))

        self.destroyNow()
        self.remove = True
        
    def searchBlock(self, block, lst, deleted):
        if block in lst:
            return
        else:
#.........这里部分代码省略.........
开发者ID:michaeltchapman,项目名称:gravbot,代码行数:103,代码来源:chunks.py

示例4: Npc

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setLinearVelocity [as 别名]

#.........这里部分代码省略.........
        material.setAmbient(VBase4(random.random(), random.random(), random.random(), random.random()))
        material.setDiffuse(VBase4(random.random(), random.random(), random.random(), random.random()))# -*- coding: utf-8 *-*
        material.setEmission(VBase4(random.random(), random.random(), random.random(), random.random()))
        #material.setSpecular(VBase4(random.random(), random.random(), random.random(), random.random()))
        material.setShininess(random.random())

        myTexture = loader.loadTexture("./textures/enemy.jpg")
        self.enemyNp.setTexture(myTexture)
        self.enemyNp.setMaterial(material)

        #bullet world
        self.world.attachRigidBody(self.enemyBulletNode)

        taskMgr.add(self.enemyUpdate, "EnemyUpdateTask#" + str(self.numNpc))

    def shoot(self):
        self.ammoUsed = 0
        self.ammoUsed += 1
        #nodes
        node = BulletRigidBodyNode('Box')
        node.setMass(.1)
        ammoNode = render.attachNewNode(node)

        #shapes
        shape = BulletSphereShape(.2)
        model = Sphere(.2)
        model.reparentTo(ammoNode)
        model.setPos(0, 0, 0)

        #nodes
        node.addShape(shape)

        material = Material()
        material.setAmbient(VBase4(random.random(), random.random(), random.random(), random.random()))
        material.setDiffuse(VBase4(random.random(), random.random(), random.random(), random.random()))
        material.setEmission(VBase4(random.random(), random.random(), random.random(), random.random()))
        material.setShininess(random.random())

        #myTexture = loader.loadTexture("player.png")
        #ammoNode.setTexture(myTexture)
        ammoNode.setMaterial(material)

        ammoNode.setX(self.enemyNp.getX())
        ammoNode.setY(self.enemyNp.getY())
        ammoNode.setZ(self.enemyNp.getZ() + 1)

        force = Vec3(0, 0, 0)
        force.setY(5)
        force.setZ(1)
        force*=50
        force = render.getRelativeVector(self.player, force)

        ammoNode.node().applyCentralForce(force)

        print(force)

        #bullet world
        self.world.attachRigidBody(node)

        #taskMgr.remove('ammoDestroy')
        task = Task(self.destroyAmmoNode)
        taskMgr.add(task, 'ammoDestroy', extraArgs = [task, ammoNode, node, self.world])
        #self.collisions.initAmmoCollisions(ammoNode, self.np, 0, 0, 0)

    def destroyAmmoNode(self, task, arg, bulletArg, world):
        if task.time > 3:
            print(task.time)
            arg.removeNode()
            world.removeRigidBody(bulletArg)
            print('mmmmm?')
            return Task.done
        return Task.cont

    def removeTask(self):
        taskMgr.remove("EnemyUpdateTask#" + str(self.numNpc))


    def enemyUpdate(self, task):
        if math.fabs(self.player.getX() - self.enemyNp.getX()) <= 20 and math.fabs(self.player.getY() - self.enemyNp.getY()) <= 20 and math.fabs(self.player.getZ() - self.enemyNp.getZ()) <= 20:
                    #self.r = random.randint(1, 100)
                    #if self.r == random.randint(1, 100):
                        #self.shoot()
                    #self.enemyLerp = LerpPosInterval(self.enemyNp, .4, self.player.getPos())
                    #self.enemyLerp.start()
            self.velocity = Vec3(self.player.getPos() - self.enemyNp.getPos())

            self.enemyBulletNode.setLinearVelocity(self.velocity * 2)

        if math.fabs(self.enemyNp.getX()) > math.fabs(self.levelNodeBounds.getRadius()) * 2:
            self.removeTask()

        if math.fabs(self.enemyNp.getY()) > math.fabs(self.levelNodeBounds.getRadius())  * 2:
            self.removeTask()

        if math.fabs(self.enemyNp.getZ()) > math.fabs(self.levelNodeBounds.getRadius())  * 2:
            self.removeTask()



        return Task.cont
开发者ID:flips30240,项目名称:VoxelDash,代码行数:104,代码来源:Npc.py

示例5: CharacterController

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setLinearVelocity [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


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