~fireclawthefox/panda3dcodecollection/trunk

« back to all changes in this revision

Viewing changes to character/extended Char controller/PhysicsInternal.py

  • Committer: Fireclaw the Fox
  • Date: 2018-01-24 20:28:43 UTC
  • Revision ID: fireclawthefox@gmail.com-20180124202843-lf17w3l0behjsbbu
Further enhanced character controller

Fixed a bunch of problems with button-press time based jumping
Added new configuration options
Further fine-tuned configurations
Added configurable extra jump direction from wall runs

extended level with new obstacles

Show diffs side-by-side

added added

removed removed

Lines of Context:
478
478
                    scale = self.max_shadow_scale
479
479
                self.shadow.setScale(scale)
480
480
 
481
 
    def doJump(self, forwardSpeed, extraSpeedVec=Vec3()):
 
481
    def doJump(self, forwardSpeed, jump_direction=Vec3(0,0,0), extraSpeedVec=Vec3()):
482
482
        """This will let the actor node jump forward on the local y-axis
483
483
        with the upward speed given in jumpForce and forward given in speed.
484
484
        Note, if the actorNode shouldn't slide after landing call the
485
485
        physics.land function with the same actorNode"""
486
486
        # as we leave the ground set the active platform, if any, to None
 
487
 
 
488
        # OLD VERSION
 
489
        '''
487
490
        self.active_platform = None
488
 
 
489
 
        #jumpVec = Vec3(0, -forwardSpeed/self.current_max_accleration*self.jump_forward_force_mult, 1)
490
 
        jumpVec = Vec3(0, -forwardSpeed/self.current_max_accleration*self.jump_forward_force_mult, 0.2)
 
491
        jumpVec = Vec3(0, -forwardSpeed/self.current_max_accleration*self.jump_forward_force_mult, 1)
491
492
        jumpVec *= self.jump_strength
492
493
 
493
494
        # rotate the extraSpeedVector to face the same direction the mainNode vector
497
498
 
498
499
        jumpVec += rotatedExtraSpeedVec
499
500
        self.actorNode.getPhysicsObject().addLocalImpulse(jumpVec)
 
501
        '''
 
502
 
 
503
 
 
504
        # NEW VERSION
 
505
        self.active_platform = None
 
506
 
 
507
        dt = globalClock.getDt()
 
508
        jumpVec = Vec3(
 
509
            0,#jump_direction.getX()*dt,
 
510
            -((forwardSpeed*self.jump_forward_force_mult))*dt,
 
511
            (self.phys_jump_strength+jump_direction.getZ())*dt)
 
512
        jumpVec *= self.jump_strength
 
513
 
 
514
        # rotate the extraSpeedVector to face the same direction the mainNode vector
 
515
        charVec = self.mainNode.getRelativeVector(render, extraSpeedVec)
 
516
        charVec.normalize()
 
517
        rotatedExtraSpeedVec = charVec * extraSpeedVec.length()
 
518
 
 
519
        jumpVec += rotatedExtraSpeedVec*dt
 
520
 
 
521
        self.actorNode.getPhysicsObject().addLocalImpulse(jumpVec)
 
522
 
 
523
        vel = self.actorNode.getPhysicsObject().getVelocity()
 
524
        velX = vel.getX()
 
525
        velY = vel.getY()
 
526
        velZ = vel.getZ()
 
527
 
 
528
        # Make sure we don't jump/move faster than we are alowed to
 
529
        #if abs(velX) > self.max_jump_force_internal_X \
 
530
        #or abs(velY) > self.max_jump_force_internal_Y:
 
531
        #    # we need to make sure X and Y are at the same distance
 
532
        #    # as before otherwise jump direction will be shifted
 
533
        #    if abs(velX) > abs(velY):
 
534
        #        pass
 
535
        #        #TODO: Calculate diff between x and y and subtract/add to respective other
 
536
        #    if velX < 0:
 
537
        #        velX = -self.max_jump_force_internal_X
 
538
        #    else:
 
539
        #        velX = self.max_jump_force_internal_X
 
540
        #if abs(velY) > self.max_jump_force_internal_Y:
 
541
        #    if velY < 0:
 
542
        #        velY = -self.max_jump_force_internal_Y
 
543
        #    else:
 
544
        #        velY = self.max_jump_force_internal_Y
 
545
        if abs(velZ) > self.max_jump_force_internal_Z:
 
546
            if velZ < 0:
 
547
                velZ = -self.max_jump_force_internal_Z
 
548
            else:
 
549
                velZ = self.max_jump_force_internal_Z
 
550
 
 
551
        self.actorNode.getPhysicsObject().setVelocity(velX, velY, velZ)
500
552
 
501
553
    def land(self):
502
554
        self.actorNode.getPhysicsObject().setVelocity(0,0,0)