def update(self):

        if not self.done:
            if self.progress >= 1.0:
                self.done = True
            else:
                self.progress += self.speed

            self.current_angle = bgeutils.interpolate_float(
                self.start, self.end, self.progress)
示例#2
0
    def update(self):

        if self.timer >= 1.0:
            self.done = True
        else:
            self.timer = min(1.0, self.timer + self.speed)
            amount = bgeutils.smoothstep(self.timer)
            self.controller.main_camera.localTransform = self.start.lerp(
                self.end, amount)
            light_in = self.controller.shadow_light_in
            light_out = self.controller.shadow_light_out
            self.controller.shadow_light.spotsize = bgeutils.interpolate_float(
                light_out, light_in, amount)
示例#3
0
    def update_dynamic_stats(self):

        if self.toggle_visible:
            self.toggle_visible = not self.toggle_visible
            self.set_visible(self.visible)

        if self.throttle > self.throttle_target:
            acceleration = 0.2
        else:
            acceleration = self.dynamic_stats["acceleration"]

        self.throttle = bgeutils.interpolate_float(self.throttle, self.throttle_target, acceleration)
        drive_mod = 1.0

        if self.reversing:
            if self.stats.drive_type == "WHEELED":
                drive_mod = 0.3
            elif self.stats.drive_type == "HALFTRACK":
                drive_mod = 0.6
            else:
                drive_mod = 0.8

        handling = self.stats.handling
        speed = self.stats.speed

        if self.off_road:
            self.dynamic_stats["handling"] = handling[1]
            self.dynamic_stats["abs_speed"] = speed[1] * 0.003
            self.dynamic_stats["acceleration"] = handling[1] * 0.002
        else:
            self.dynamic_stats["handling"] = handling[0]
            self.dynamic_stats["abs_speed"] = speed[0] * 0.003
            self.dynamic_stats["acceleration"] = handling[0] * 0.002

        self.dynamic_stats["speed"] = (self.dynamic_stats["abs_speed"] * drive_mod) * self.throttle
        self.dynamic_stats["turning_speed"] = self.dynamic_stats["acceleration"] * 0.8
        self.dynamic_stats["display_speed"] = self.dynamic_stats["speed"] * 4.0

        if self.reversing:
            self.dynamic_stats["display_speed"] *= -1.0
    def update(self):

        throttle = self.agent.throttle
        throttle_target = self.agent.throttle_target
        throttle_difference = (throttle - throttle_target) * 0.05

        if self.agent.reversing:
            throttle_difference *= -1.0

        throttle_difference = min(0.02, max(-0.02, throttle_difference))

        self.tilt = bgeutils.interpolate_float(self.tilt, throttle_difference,
                                               0.03)
        self.recoil = self.recoil.lerp(mathutils.Vector([0.0, 0.0, 0.0]),
                                       self.damping * 0.1)

        point = self.agent.box.worldPosition.copy()
        start_height = self.start_hit.point.z
        end_height = self.end_hit.point.z

        if self.agent.movement:
            progress = self.agent.movement.progress
            point.z = bgeutils.interpolate_float(start_height, end_height,
                                                 progress)
            normal = self.start_hit.normal.lerp(self.end_hit.normal, progress)

        else:
            point.z = start_height
            normal = self.start_hit.normal

        self.agent.hull.worldPosition = self.agent.hull.worldPosition.copy(
        ).lerp(point, 0.8)

        if self.agent.on_screen:
            self.agent.screen_position = self.agent.box.scene.active_camera.getScreenPosition(
                self.agent.box)

            if self.vehicle:
                local_y = self.agent.hull.getAxisVect([0.0, 1.0, 0.0])

                z = self.recoil + mathutils.Vector([0.0, self.tilt, 1.0])
                local_z = self.agent.hull.getAxisVect(z)

                target_vector = local_z.lerp(normal, self.damping)

                self.agent.hull.alignAxisToVect(local_y, 1, 1.0)
                self.agent.hull.alignAxisToVect(target_vector, 2, 1.0)

                # do slopes later
                slope = normal.copy()
                slope.z = 0.0
                self.slope = slope

                speed = self.agent.dynamic_stats["display_speed"]

                self.trails.movement_trail(abs(speed))

            else:
                local_y = self.agent.hull.getAxisVect([0.0, 1.0, 0.0])
                local_z = self.agent.hull.getAxisVect([0.0, 0.0, 1.0])

                target_vector = local_z.lerp(normal, self.damping)
                self.agent.hull.alignAxisToVect(local_y, 1, 1.0)
                self.agent.hull.alignAxisToVect(target_vector, 2, 1.0)

            if self.agent.display_object:
                self.agent.display_object.game_update()

        else:
            self.agent.screen_position = None