Ejemplo n.º 1
0
	def update(self, stepSize):
		"""
		I use "forward" for standing up from a chair.
		"""
		if self.isSitting:
			if inputState.isSet("forward"):
				self.standUpFromChair()
			return
		elif self.isDisabled:
			return
		else:
			base.cam.setPos(self.geom.getPosition() + Vec3(0, 0, self.camH))
		
		moveAtSpeed = 6.0
		self.speed = [0.0, 0.0]
		
		"""
		Handle input. Note that in the main.py file there's this line:
			base.buttonThrowers[0].node().setModifierButtons(ModifierButtons())
		It is very important to make sure you can, for example, walk forward,
		strafe and jump at the same time.
		"""
		if inputState.isSet("run"): moveAtSpeed = moveAtSpeed * 2

		if inputState.isSet("forward" ): self.speed[1] = moveAtSpeed
		if inputState.isSet("backward" ): self.speed[1] = -moveAtSpeed
		if inputState.isSet("strafeLeft"): self.speed[0] = -moveAtSpeed
		if inputState.isSet("strafeRight"): self.speed[0] = moveAtSpeed
		
		if inputState.isSet("crouch"):
			self.crouch()
		else:
			self.crouchStop()
		
		kinematicCharacterController.update(self, stepSize)
		
		"""
		Update the held object
		"""
		if self.heldItem:
			self.placeObjectInFrontOfCamera(self.heldItem)
			
			if self.heldItem.body:
				self.heldItem.body.enable()
				
				self.heldItem.body.setLinearVel(Vec3(*[0.0]*3))
				self.heldItem.body.setAngularVel(Vec3(*[0.0]*3))
Ejemplo n.º 2
0
	def update(self, stepSize):
		"""
		I use "forward" for standing up from a chair.
		"""
		if self.isSitting:
			camPos = base.cam.getPos(render)
			camQuat = base.cam.getQuat(render)
			self.updateAimCollisions(camPos, camQuat)
			
			if inputState.isSet("forward"):
				self.standUpFromChair()
			return
		elif self.isDisabled:
			return
		
		# MOVEMENT
		"""
		Handle input. Note that in the main.py file there's this line:
			base.buttonThrowers[0].node().setModifierButtons(ModifierButtons())
		It is very important to make sure you can, for example, walk forward,
		strafe and jump at the same time.
		"""
		newLinearVelocity = Vec3(0,0,0)
		
		moveAtSpeed = self.walkSpeed
		if inputState.isSet("run"): moveAtSpeed = self.runSpeed
		
		if inputState.isSet("forward" ): newLinearVelocity[1] = moveAtSpeed
		if inputState.isSet("backward" ): newLinearVelocity[1] = -moveAtSpeed
		if inputState.isSet("strafeLeft"): newLinearVelocity[0] = -moveAtSpeed
		if inputState.isSet("strafeRight"): newLinearVelocity[0] = moveAtSpeed
		
		
		if self.state == "fly":
			self.linearVelocity = base.cam.getQuat(render).xform(newLinearVelocity)
		else:
			self.linearVelocity = self.movementParent.getQuat(render).xform(newLinearVelocity)
		
		if inputState.isSet("crouch"):
			self.crouch()
		else:
			self.crouchStop()
		
		self.currentPos += self.linearVelocity * stepSize
		
		kinematicCharacterController.update(self, stepSize)
		
		# CAMERA
		camPos = self.currentPos + Vec3(0, 0, self.cameraHeight)
		camQuat = base.cam.getQuat(render)
		
		print camPos
		from interpreter import cliClass
		interpreter = cliClass()
		interpreter.sendPos(camPos)
    	
		base.cam.setX(camPos[0])
		base.cam.setY(camPos[1])
		
		if not self.cameraSteppingAnim:
			if self.state == "ground":		
				fromH = base.cam.getPos(render)[2]
				toH = camPos[2]
				
				self.cameraSteppingAnim = Sequence(
					LerpFunc(self.cameraAnimation, fromData = fromH, toData = toH, duration = 0.1),
					Func(self.clearCameraAnimation)
					)
				self.cameraSteppingAnim.start()
			else:
				base.cam.setZ(camPos[2])
		
		self.movementParent.setH(base.cam.getH(render))
		
		# AIMING
		self.updateAimCollisions(camPos, camQuat)
		
		# HELD ITEM
		held = self.heldItem
		if held:
			self.placeObjectInFrontOfCamera(held)
			
			if held.body and held.pickableType == "carry":
				held.body.enable()
				
				held.body.setLinearVel(Vec3(*[0.0]*3))
				held.body.setAngularVel(Vec3(*[0.0]*3))