Beispiel #1
0
    def tick(self, dtime):
        #----------position-----------------------------------
        timeScaledAcceleration = self.ent.acceleration * (dtime * 100)
        self.ent.speed += utils.clamp(self.ent.desiredSpeed - self.ent.speed,
                                      -timeScaledAcceleration,
                                      timeScaledAcceleration)

        #self.ent.vel.x = math.cos(-self.ent.heading) * self.ent.speed
        #self.ent.vel.z = math.sin(-self.ent.heading) * self.ent.speed
        #self.ent.vel.y = 0

        self.ent.vel = Vector3(self.ent.speed * math.cos(-self.ent.heading), 0,
                               self.ent.speed * math.sin(-self.ent.heading))

        self.ent.pos = self.ent.pos + (self.ent.vel * dtime)

        #------------heading----------------------------------

        timeScaledRotation = self.ent.turningRate * (dtime * 20)
        angleDiff = utils.diffAngle(self.ent.desiredHeading, self.ent.heading)
        dheading = utils.clamp(angleDiff, -timeScaledRotation,
                               timeScaledRotation)
        print self.ent.desiredHeading
        print "meow"
        print self.ent.heading
        self.ent.heading += dheading
 def tick(self, dtime):
     # Set Target Point
     point = Vector3(0, self.target.pos.y + self.height, 0)
     angleRad = math.radians(utils.diffAngle(self.target.yaw, -self.angle))
     point.x = self.target.pos.x + self.offset * math.cos(angleRad)
     point.z = self.target.pos.z + self.offset * -math.sin(angleRad)
     # Check Planar Distance
     self.ent.distance = math.sqrt((point.x - self.ent.pos.x)**2 + (point.z - self.ent.pos.z)**2)
     # Set Planar Orientation (Yaw)
     self.ent.desiredYaw = self.getDesiredHeadingToTargetPosition(point)
     # Check Distance
     if self.ent.distance < 100:
         if math.fabs(utils.diffAngle(self.ent.yaw, self.ent.desiredYaw)) < 90:
             self.ent.desiredSpeed = self.target.speed
         else:
             self.ent.desiredSpeed = self.ent.maxSpeed - math.fabs(self.ent.speed - self.ent.maxSpeed)
             self.ent.desiredYaw = self.target.yaw
     else:
         self.ent.desiredSpeed = self.ent.maxSpeed
     # Height Difference (Pitch)
     self.ent.difference = self.ent.pos.y - point.y
     self.ent.desiredPitch = math.degrees(math.atan2(-self.ent.difference, self.ent.distance))
    def tick(self, dtime):
        ''' Updates Position, Yaw, Pitch, and Roll. '''
        # Position ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
        timeScaledAcceleration = self.ent.acceleration * dtime
        self.ent.speed += utils.clamp( self.ent.desiredSpeed - self.ent.speed, -timeScaledAcceleration, timeScaledAcceleration)
        self.ent.vel.y = self.ent.speed * math.sin( math.radians( self.ent.pitch ) )
        ## xz = self.ent.speed * math.cos( math.radians( self.ent.pitch ) )
        self.ent.vel.x = self.ent.speed * math.cos( math.radians( self.ent.yaw ) )
        self.ent.vel.z = self.ent.speed * -math.sin( math.radians( self.ent.yaw ) )
        self.ent.pos = self.ent.pos + ( self.ent.vel * dtime )

        # Yaw ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
        timeScaledYaw = self.ent.yawRate * dtime
        angleDiff = utils.diffAngle(self.ent.desiredYaw, self.ent.yaw)
        self.ent.deltaYaw = utils.clamp(angleDiff, -timeScaledYaw, timeScaledYaw)
        ## print '---' + self.ent.uiname + '---'
        ## print "angleDiff: %f, timeScaledYaw: %f,  deltaYaw: %f " % (angleDiff, timeScaledYaw, self.ent.deltaYaw )
        ## print "yaw: %f, desiredYaw: %f, yawRate: %f" % (self.ent.yaw, self.ent.desiredYaw, self.ent.yawRate)
        self.ent.yaw = utils.fixAngle( self.ent.yaw + self.ent.deltaYaw)
        # Pitch ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
        timeScaledPitch = self.ent.pitchRate * dtime
        angleDiff = utils.diffAngle(self.ent.desiredPitch, self.ent.pitch)
        self.ent.deltaPitch = utils.clamp(angleDiff, -timeScaledPitch, timeScaledPitch)
        ## print "angleDiff: %f, timeScaledPitch: %f,  deltaPitch: %f " % (angleDiff, timeScaledPitch, self.ent.deltaPitch )
        ## print "pitch: %f, desiredPitch: %f, pitchRate: %f" % (self.ent.pitch, self.ent.desiredPitch, self.ent.pitchRate)
        self.ent.pitch = utils.fixAngle( self.ent.pitch + self.ent.deltaPitch)
        # Roll ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
        if dtime > 0.001:
            self.ent.desiredRoll = -self.ent.deltaYaw / dtime * 0.75
        timeScaledRoll = self.ent.rollRate * dtime
        angleDiff = utils.diffAngle(self.ent.desiredRoll, self.ent.roll)
        self.ent.deltaRoll = utils.clamp(angleDiff, -timeScaledRoll, timeScaledRoll)
        ## print "angleDiff: %f, timeScaledRoll: %f,  dRoll: %f " % (angleDiff, timeScaledRoll, self.ent.deltaRoll )
        ## print "roll: %f, desiredRoll: %f, rollRate: %f" % (self.ent.roll, self.ent.desiredRoll, self.ent.rollRate)
        ## print "---"
        self.ent.roll = utils.fixAngle( self.ent.roll + self.ent.deltaRoll)
        
# Physics -------------------------------------------------------------------- #
Beispiel #4
0
    def tick(self, dtime):
        #----------position-----------------------------------
        timeScaledAcceleration = self.ent.acceleration * dtime
        if self.ent.uiname != 'bear':
            self.ent.speed += utils.clamp( self.ent.desiredSpeed - self.ent.speed, -timeScaledAcceleration, timeScaledAcceleration)
    
            self.ent.vel.x = ogre.Math.Cos(-self.ent.heading) * self.ent.speed
            self.ent.vel.z = ogre.Math.Sin(-self.ent.heading) * self.ent.speed
            self.ent.vel.y = 0
        
        self.ent.pos = self.ent.pos + (self.ent.vel * dtime)

        #------------heading----------------------------------

        timeScaledRotation = self.ent.turningRate * dtime
        angleDiff = utils.diffAngle(self.ent.desiredHeading, self.ent.heading)
        dheading = utils.clamp(angleDiff, -timeScaledRotation, timeScaledRotation)

        self.ent.heading += dheading
        
        angleDiff = utils.diffAngle(self.ent.desiredPitch, self.ent.pitch)
        dheading = utils.clamp(angleDiff, -timeScaledRotation, timeScaledRotation)

        self.ent.pitch += dheading
 def tick(self, dtime):
     # Check Planar Distance
     self.ent.distance = math.sqrt((self.target.pos.x - self.ent.pos.x)**2 + (self.target.pos.z - self.ent.pos.z)**2)
     # Set Planar Orientation (Yaw)
     self.ent.desiredYaw = self.getDesiredHeadingToTargetPosition(self.target.pos)
     # Check Distance
     if self.ent.distance < 100:
         if math.fabs(utils.diffAngle(self.ent.yaw, self.ent.desiredYaw)) < 90:
             self.ent.desiredSpeed = self.target.speed
         else:
             self.ent.desiredSpeed = self.ent.maxSpeed - math.fabs(self.ent.speed - self.ent.maxSpeed)
             self.ent.desiredYaw = self.target.yaw
     else:
         self.ent.desiredSpeed = self.ent.maxSpeed
     # Height Difference (Pitch)
     difference = self.target.pos.y - self.ent.pos.y
     self.ent.desiredPitch = math.degrees(math.atan2(difference, self.ent.distance))
Beispiel #6
0
    def tick(self, dtime):
        #----------position-----------------------------------
        timeScaledAcceleration = self.ent.acceleration * dtime
        self.ent.speed += utils.clamp( self.ent.desiredSpeed - self.ent.speed, -timeScaledAcceleration, timeScaledAcceleration)

        self.ent.vel.x = math.cos(-self.ent.heading) * self.ent.speed
        self.ent.vel.z = math.sin(-self.ent.heading) * self.ent.speed
        self.ent.vel.y = 0
        
        self.ent.pos = self.ent.pos + (self.ent.vel * dtime)

        #------------heading----------------------------------

        timeScaledRotation = self.ent.turningRate * dtime
        angleDiff = utils.diffAngle(self.ent.desiredHeading, self.ent.heading)
        dheading = utils.clamp(angleDiff, -timeScaledRotation, timeScaledRotation)

        self.ent.heading += dheading
 def tick(self, dtime):
     # Check Planar Distance
     self.ent.distance = math.sqrt((self.target.pos.x - self.ent.pos.x)**2 + (self.target.pos.z - self.ent.pos.z)**2)
     # Check Distance
     if self.ent.distance < 75:
         # Explode
         self.target.damage(self.ent.explodeDmg)
         self.ent.damage(self.ent.explodeDmg)
         self.ent.unitai.addCommand( Explode(self.ent) )
         return True
     # Set Planar Orientation (Yaw)
     self.ent.desiredYaw = self.getDesiredHeadingToTargetPosition(self.target.pos)
     
     # Check Relative Position
     angle = utils.diffAngle(self.ent.yaw, self.ent.desiredYaw)
     if math.fabs( angle) > 90:
         self.ent.desiredSpeed = self.ent.maxSpeed - math.fabs(self.ent.speed - self.ent.maxSpeed)
         self.ent.desiredYaw = self.target.yaw
     else:
         self.ent.desiredSpeed = self.ent.maxSpeed
     # Height Difference (Pitch)
     difference = self.target.pos.y - self.ent.pos.y
     self.ent.desiredPitch = math.degrees(math.atan2(difference, self.ent.distance))
Beispiel #8
0
    def tick(self, dtime):
        #----------position-----------------------------------
        timeScaledAcceleration = self.ent.acceleration * (dtime * 100)
        self.ent.speed += utils.clamp( self.ent.desiredSpeed - self.ent.speed, -timeScaledAcceleration, timeScaledAcceleration)

        #self.ent.vel.x = math.cos(-self.ent.heading) * self.ent.speed
        #self.ent.vel.z = math.sin(-self.ent.heading) * self.ent.speed
        #self.ent.vel.y = 0


        self.ent.vel = Vector3(self.ent.speed * math.cos(-self.ent.heading), 0, self.ent.speed * math.sin(-self.ent.heading))
        
        self.ent.pos = self.ent.pos + (self.ent.vel * dtime)

        #------------heading----------------------------------

        timeScaledRotation = self.ent.turningRate * (dtime*20)
        angleDiff = utils.diffAngle(self.ent.desiredHeading, self.ent.heading)
        dheading = utils.clamp(angleDiff, -timeScaledRotation, timeScaledRotation)
	print self.ent.desiredHeading
	print "meow"
	print self.ent.heading
        self.ent.heading += dheading
    def tick(self, dtime):

	if (self.ent.mesh == "sphere.mesh"):
            self.ent.vel.z = -math.cos(self.ent.heading)*self.ent.speed
            self.ent.vel.x = -math.sin(self.ent.heading)*self.ent.speed
            if self.ent.pitch != 0:
                self.ent.vel.y = self.ent.speed*math.tan(-self.ent.pitch)
            else:
                self.ent.vel.y = 0
             
            self.ent.pos = self.ent.pos + (self.ent.vel * dtime)
            squaredDistance = (self.ent.pos - self.ent.initialPos).squaredLength()
            if  squaredDistance > self.ent.distance**2:
                self.ent.isGone = True

            if self.ent.pos.y <= 0:
                self.ent.isGone = True
 
        elif self.ent.mesh == "ninja.mesh":
            #------------position--------------------------------
            self.ent.vel.z = -math.cos(self.ent.heading) * self.ent.speed
            self.ent.vel.x = -math.sin(self.ent.heading) * self.ent.speed
            self.ent.vel.y = 0
            self.ent.pos = self.ent.pos + (self.ent.vel * dtime)
            self.ent.heading = utils.fixAngle(self.ent.heading)

            if self.ent.speed != 0:
                self.ent.move = True
            else:
                self.ent.move = False
                self.ent.speed = 0

        elif (self.ent.mesh == "robot.mesh"):
 
            self.ent.move = False
            self.ent.speed = 0
            self.ent.lockOn = False

            if not self.ent.engine.gfxMgr.game3:
                self.game1(dtime)
            else:
                self.game1(dtime)
                self.game3(dtime)

            if self.ent.lockOn:
                self.ent.pos = self.ent.pos + self.ent.vel*dtime

            # update heading 
            if abs(self.ent.desiredHeading - self.ent.heading) >= 0.01:
                self.ent.heading = utils.fixAngle(self.ent.heading)
                timeScaledRotation = self.ent.turningRate * dtime
                angleDiff = utils.diffAngle(self.ent.desiredHeading, self.ent.heading)
                dheading = utils.clamp(angleDiff, -timeScaledRotation, timeScaledRotation)
                self.ent.heading += dheading
            else:
                self.ent.causion = False	


        elif self.ent.mesh == "shield.mesh":
            #-------------------------Bobbing-------------#
            if self.ent.pos.y < self.ent.bobMax and self.ent.bobReset == False:
                self.ent.pos.y += dtime*12
            elif self.ent.bobReset == True:
                self.ent.pos.y -= dtime*12

            if self.ent.pos.y >= self.ent.bobMax:
                self.ent.bobReset = True
            elif self.ent.pos.y <= self.ent.bobMin:
                self.ent.bobReset = False

            self.ent.heading += dtime