def run(self, my_car, packet, agent): car_location = Vec3(my_car.physics.location) vertical_vel = my_car.physics.velocity.z controls = SimpleControllerState() controls.yaw = steer_toward_target( my_car, self.target, -my_car.physics.angular_velocity.z / 6) controls.boost = not (vertical_vel < 0 and car_location.z > 40 and self.tick < 20) controls.use_item = car_location.dist( Vec3(packet.game_ball.physics.location )) < 200 and relative_location( car_location, Orientation(my_car.physics.rotation), Vec3(packet.game_ball.physics.location)).z < 75 if self.tick == 0: controls.jump = True self.tick = 1 else: if self.tick <= 10: self.tick += 1 elif my_car.has_wheel_contact: agent.stack.pop() if vertical_vel < 0 and car_location.z > 40 and self.tick < 20: self.tick += 1 controls.pitch = 1 if vertical_vel < 0 and car_location.z < 40: controls.jump = True controls.pitch = -1 controls.yaw = 0 return controls
def update(self): if self.agent.me.location[2] < 600: if self.agent.onSurface or self.agent.me.location[2] < 100: self.active = False controller_state = SimpleControllerState() if self.agent.me.rotation[2] > 0: controller_state.roll = -1 elif self.agent.me.rotation[2] < 0: controller_state.roll = 1 if self.agent.me.rotation[0] > self.agent.velAngle: controller_state.yaw = -1 elif self.agent.me.rotation[0] < self.agent.velAngle: controller_state.yaw = 1 if self.active: controller_state.throttle = 1 else: controller_state.throttle = 0 else: controller_state = SimpleControllerState() return controller_state
def exec(self, bot) -> SimpleControllerState: ct = time.time() - self._start_time controls = SimpleControllerState() controls.throttle = 1 car = bot.data.my_car # Target is allowed to be a function that takes bot as a parameter. Check what it is if callable(self.target): target = self.target(bot) else: target = self.target # To boost or not to boost, that is the question car_to_target = target - car.pos vel_p = proj_onto_size(car.vel, car_to_target) angle = angle_between(car_to_target, car.forward()) controls.boost = self.boost and angle < self._boost_ang_req and vel_p < self._max_speed # States of dodge (note reversed order) # Land on ground if ct >= self._t_finishing: self._almost_finished = True if car.on_ground: self.done = True else: bot.maneuver = RecoveryManeuver(bot) self.done = True return controls elif ct >= self._t_second_unjump: # Stop pressing jump and rotate and wait for flip is done pass elif ct >= self._t_aim: if ct >= self._t_second_jump: controls.jump = 1 # Direction, yaw, pitch, roll if self.target is None: controls.roll = 0 controls.pitch = -1 controls.yaw = 0 else: target_local = dot(car_to_target, car.rot) target_local.z = 0 direction = normalize(target_local) controls.roll = 0 controls.pitch = -direction.x controls.yaw = sign(car.rot.get(2, 2)) * direction.y # Stop pressing jump elif ct >= self._t_first_unjump: pass # First jump else: controls.jump = 1 return controls
def frugalController(agent, target, speed): controller_state = SimpleControllerState() location = toLocal(target, agent.me) angle_to_target = math.atan2(location.data[1], location.data[0]) controller_state.steer = steer(angle_to_target) speed -= ((angle_to_target**2) * 300) current_speed = velocity1D(agent.me).data[1] if current_speed < speed: controller_state.throttle = 1.0 elif current_speed - 50 > speed: controller_state.throttle = -1.0 else: controller_state.throttle = 0 time_difference = time.time() - agent.start if time_difference > 2.2 and distance2D( target, agent.me) > (velocity2D(agent.me) * 2.3) and abs( angle_to_target ) < 0.9 and current_speed < speed and current_speed > 220: agent.start = time.time() elif time_difference <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_difference >= 0.1 and time_difference <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_difference > 0.15 and time_difference < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 return controller_state
def exampleController(agent, target_object, target_speed): location = toLocal(target_object, agent.me) controller_state = SimpleControllerState() angle_to_ball = math.atan2(location.data[1], location.data[0]) current_speed = velocity2D(agent.me) #steering controller_state.steer = steer(angle_to_ball) #throttle if target_speed > current_speed: controller_state.throttle = 1.0 if target_speed > 1400 and agent.start > 2.2 and current_speed < 2250: controller_state.boost = True elif target_speed < current_speed: controller_state.throttle = 0 #dodging time_difference = time.time() - agent.start if time_difference > 2.2 and distance2D(target_object, agent.me) > ( velocity2D(agent.me) * 2.5) and abs(angle_to_ball) < 1.3: agent.start = time.time() elif time_difference <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_difference >= 0.1 and time_difference <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_difference > 0.15 and time_difference < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 return controller_state
def fix_orientation(data: Data, point=None): controller = SimpleControllerState() strength = 0.22 ori = data.car.orientation if point is None and data.car.velocity.flat().length2() != 0: point = data.car.location + data.car.velocity.flat().rescale(500) pitch_error = -ori.pitch * strength controller.pitch = data.agent.pid_pitch.calc(pitch_error) roll_error = -ori.roll * strength controller.roll = data.agent.pid_roll.calc(roll_error) if point is not None: # yaw rotation can f up the other's so we scale it down until we are more confident about landing on the wheels car_to_point = point - data.car.location yaw_error = ori.front.ang_to_flat(car_to_point) * strength * 1.5 land_on_wheels01 = 1 - ori.up.ang_to(UP) / (math.pi * 2) controller.yaw = data.agent.pid_yaw.calc(yaw_error) * (land_on_wheels01 **6) # ! controller.throttle = 1 return controller
def input(self): controller_input = SimpleControllerState() current_angle_vec = Vec3(cos(self.current_state.rot.yaw), sin(self.current_state.rot.yaw), 0) goal_angle_vec = Vec3(cos(self.goal_state.rot.yaw), sin(self.goal_state.rot.yaw), 0) vel_2d = Vec3(self.current_state.vel.x, self.current_state.vel.y, 0) if (self.current_state.pos - self.goal_state.pos).magnitude() > 400: #Turn towards target. Hold throttle until we're close enough to start stopping. controller_input = GroundTurn(self.current_state, self.goal_state).input() elif vel_2d.magnitude() < 50 and current_angle_vec.dot(goal_angle_vec) < 0: #If we're moving slowly, but not facing the right way, jump to turn in the air. #Decide which way to turn. Make sure we don't have wraparound issues. goal_x = goal_angle_vec.x goal_y = goal_angle_vec.y car_theta = self.current_state.rot.yaw #Rotated to the car's reference frame on the ground. rel_vector = Vec3((goal_x*cos(car_theta)) + (goal_y * sin(car_theta)), (-(goal_x*sin(car_theta))) + (goal_y * cos(car_theta)), 0) correction_angle = atan2(rel_vector.y, rel_vector.x) #Jump and turn to reach goal yaw. if self.current_state.wheel_contact: controller_input.jump = 1 else: controller_input.yaw = cap_magnitude(correction_angle, 1) elif self.current_state.vel.magnitude() > 400: #TODO: Proportional controller to stop in the right place controller_input.throttle = -1 else: #Wiggle to face ball #Check if the goal is ahead of or behind us, and throttle in that direction goal_angle = atan2((self.goal_state.pos - self.current_state.pos).y, (self.goal_state.pos - self.current_state.pos).x) if abs(angle_difference(goal_angle,self.current_state.rot.yaw)) > pi/2: correction_sign = -1 else: correction_sign = 1 controller_input.throttle = correction_sign #Correct as we wiggle so that we face goal_yaw. if angle_difference(self.goal_state.rot.yaw, self.current_state.rot.yaw) > 0: angle_sign = 1 else: angle_sign = -1 controller_input.steer = correction_sign*angle_sign return controller_input
def waitController(agent, target, speed): controller_state = SimpleControllerState() loc = toLocal(target, agent.me) angle_to_target = math.atan2(loc.data[1], loc.data[0]) controller_state.steer = steer(angle_to_target) current_speed = velocity2D(agent.me) if current_speed < speed: controller_state.throttle = 1.0 elif current_speed - 50 > speed: controller_state.throttle = -1.0 else: controller_state.throttle = 0 time_diff = time.time() - agent.start if time_diff > 2.2 and distance2D(target,agent.me) > (velocity2D(agent.me)*2.3) and abs(angle_to_target) < 1 and current_speed < speed: agent.start = time.time() elif time_diff <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_diff >= 0.1 and time_diff <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_diff > 0.15 and time_diff < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 return controller_state
def controller(self, agent): controller_state = SimpleControllerState() controller_state.pitch = 1 controller_state.throttle = -1 self.time_difference = agent.game_info.seconds_elapsed - self.start if self.time_difference <= 0.1: controller_state.jump = True elif 0.1 <= self.time_difference <= 0.15: controller_state.jump = False elif 0.15 <= self.time_difference <= 0.35: controller_state.jump = True elif 0.4 <= self.time_difference <= 1.75: controller_state.pitch = -1 if 1.2 <= self.time_difference: controller_state.throttle = 1 if 0.575 <= self.time_difference <= 1.2: controller_state.boost = True controller_state.roll = 1 if 0.7 <= self.time_difference <= 1.5: controller_state.yaw = .5 return controller_state
def get_controller_state_from_actions( action: np.ndarray) -> SimpleControllerState: controls = action.clip(-1, 1) controller_state = SimpleControllerState() controller_state.pitch = controls[0] controller_state.yaw = controls[1] controller_state.roll = controls[2] controller_state.boost = bool(controls[3] >= 0) return controller_state
def update(self): if self.agent.onSurface or self.agent.me.location[2] < 100: self.active = False controller_state = SimpleControllerState() # if self.agent.me.rotation[1] > 0: # controller_state.pitch = 1 # # elif self.agent.me.rotation[1] < 0: # controller_state.pitch = -1 if self.agent.me.rotation[2] > 0: controller_state.roll = -1 elif self.agent.me.rotation[2] < 0: controller_state.roll = 1 if self.agent.me.rotation[0] > self.agent.velAngle: controller_state.yaw = -1 elif self.agent.me.rotation[0] < self.agent.velAngle: controller_state.yaw = 1 # if self.agent.me.avelocity[0] > 2: # controller_state.yaw = -1 # elif self.agent.me.avelocity[0] < 2: # controller_state.yaw = 1 # # if self.agent.me.avelocity[1] > 2: # controller_state.pitch= 1 # elif self.agent.me.avelocity[1] < 2: # controller_state.pitch = -1 # # if self.agent.me.avelocity[2] > 2: # controller_state.roll = -1 # elif self.agent.me.avelocity[2] < 2: # controller_state.roll = 1 if self.active: controller_state.throttle = 1 else: controller_state.throttle = 0 return controller_state
def exampleController(self, target_object, target_speed): location = target_object.local_location controller_state = SimpleControllerState() angle_to_ball = math.atan2(location.data[1], location.data[0]) current_speed = velocity2D(self.me) #team team = sign(self.team) # if team<=0: #blue #try to get the ball to orange goal #else: #orange #try to get the ball to blue goal #steering if angle_to_ball > 0.1: controller_state.steer = controller_state.yaw = 1 elif angle_to_ball < -0.1: controller_state.steer = controller_state.yaw = -1 else: controller_state.steer = controller_state.yaw = 0 #powersliding if angle_to_ball > 0.8: controller_state.handbrake = True elif angle_to_ball < -0.8: controller_state.handbrake = True else: controller_state.handbrake = False #throttle if target_speed > current_speed: controller_state.throttle = 1.0 if target_speed > 1400 and self.start > 2.2 and current_speed < 2250: controller_state.boost = True elif target_speed < current_speed: controller_state.throttle = 0 #dodging front only time_difference = time.time() - self.start if time_difference > 2.2 and distance2D( target_object.location, self.me.location) > 1000 and abs(angle_to_ball) < 1.3: self.start = time.time() elif time_difference <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_difference >= 0.1 and time_difference <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_difference > 0.15 and time_difference < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 return controller_state
def to_simple_controller_state(self): controls = SimpleControllerState() controls.throttle = self.throttle controls.steer = self.steer controls.yaw = self.yaw controls.pitch = self.pitch controls.roll = self.roll controls.boost = self.boost controls.jump = self.jump controls.handbrake = self.handbrake return controls
def recoveryController(agent, local): #accepts agent, the agent's controller, and a target (in local coordinates) controller_state = SimpleControllerState() turn = math.atan2(local.data[1],local.data[0]) up = toLocal(agent.me.location + Vector3([0,0,100]), agent.me) target = [math.atan2(up.data[1],up.data[2]), math.atan2(local.data[2],local.data[0]), turn] #determining angles each axis must turn controller_state.steer = steerPD(turn, 0) controller_state.yaw = steerPD(target[2],-agent.me.rvelocity.data[2]/5) controller_state.pitch = steerPD(target[1],agent.me.rvelocity.data[1]/5) controller_state.roll = steerPD(target[0],agent.me.rvelocity.data[0]/5) return controller_state
def getSensible_thingToCONTROL(magicWariable): ThisISTHE_controller = SimpleControllerState() ThisISTHE_controller.throttle = magicWariable[magicWariable[0][0]] ThisISTHE_controller.steer = magicWariable[magicWariable[0][1]] ThisISTHE_controller.pitch = magicWariable[magicWariable[0][2]] ThisISTHE_controller.yaw = magicWariable[magicWariable[0][3]] ThisISTHE_controller.roll = magicWariable[magicWariable[0][4]] ThisISTHE_controller.jump = magicWariable[magicWariable[0][5]] ThisISTHE_controller.boost = magicWariable[magicWariable[0][6]] ThisISTHE_controller.handbrake = magicWariable[magicWariable[0][7]] return ThisISTHE_controller
def update(self): controller_state = SimpleControllerState() jump = flipHandler(self.agent, self.flip_obj) if jump: if self.targetCode == 1: controller_state.pitch = -1 controller_state.steer = 0 controller_state.throttle = 1 elif self.targetCode == 0: ball_local = toLocal(self.agent.ball.location, self.agent.me) ball_angle = math.atan2(ball_local.data[1], ball_local.data[0]) controller_state.jump = True controller_state.yaw = math.sin(ball_angle) pitch = -math.cos(ball_angle) controller_state.pitch = pitch if pitch > 0: controller_state.throttle = -1 else: controller_state.throttle = 1 elif self.targetCode == 2: controller_state.pitch = 0 controller_state.steer = 0 controller_state.yaw = 0 elif self.targetCode == 3: controller_state.pitch = 1 controller_state.steer = 0 controller_state.throttle = -1 elif self.targetCode == -1: controller_state.pitch = 0 controller_state.steer = 0 controller_state.throttle = 0 controller_state.jump = jump controller_state.boost = False if self.flip_obj.flipDone: self.active = False return controller_state
def deltaC(agent, target): c = SimpleControllerState() target = target # - agent.me.velocity target_local = toLocal(agent.me.location + target, agent.me) angle_to_target = math.atan2(target_local.data[1], target_local.data[0]) pitch_to_target = math.atan2(target_local.data[2], target_local.data[0]) if agent.me.grounded: if agent.jt + 1.5 > time.time(): c.jump = True else: c.jump = False agent.jt = time.time() else: c.yaw = steerPD(angle_to_target, -agent.me.rvelocity.data[1] / 4) c.pitch = steerPD(pitch_to_target, agent.me.rvelocity.data[0] / 4) if target.magnitude() > 10: c.boost = True if abs(pitch_to_target) + abs(angle_to_target) > 0.9: c.boost = False else: top = toLocal([ agent.me.location.data[0], agent.me.location.data[1], agent.me.location.data[2] + 1000 ], agent.me) roll_to_target = math.atan2(top.data[1], top.data[2]) c.roll = steerPD(roll_to_target, agent.me.rvelocity.data[2] * 0.5) tsj = time.time() - agent.jt if tsj < 0.215: c.jump = True elif tsj < 0.25: c.jump = False elif tsj >= 0.25 and tsj < 0.27 and target.data[2] > 560: c.jump = True c.boost = False c.yaw = 0 c.pitch = 0 c.roll = 0 else: c.jump = False return c
def shotController(agent, target_object, target_speed): goal_local = toLocal([0, -sign(agent.team) * FIELD_LENGTH / 2, 100], agent.me) goal_angle = math.atan2(goal_local.data[1], goal_local.data[0]) location = toLocal(target_object, agent.me) controller_state = SimpleControllerState() angle_to_target = math.atan2(location.data[1], location.data[0]) current_speed = velocity2D(agent.me) #steering controller_state.steer = steer(angle_to_target) #throttle if target_speed > 1400 and target_speed > current_speed and agent.start > 2.5 and current_speed < 2250: controller_state.boost = True if target_speed > current_speed: controller_state.throttle = 1.0 elif target_speed < current_speed: controller_state.throttle = 0 #dodging time_difference = time.time( ) - agent.start # how long its been since we last dodged if ballReady(agent) and time_difference > 2.2 and distance2D( target_object, agent.me) <= 270: agent.start = time.time() elif time_difference <= 0.1: controller_state.jump = True controller_state.yaw = math.sin(goal_angle) controller_state.pitch = -abs(math.cos(goal_angle)) elif time_difference >= 0.1 and time_difference <= 0.13: controller_state.jump = False controller_state.yaw = math.sin(goal_angle) controller_state.pitch = -abs(math.cos(goal_angle)) elif time_difference > 0.13 and time_difference < 1: controller_state.jump = True controller_state.yaw = math.sin(goal_angle) controller_state.pitch = -abs(math.cos(goal_angle)) return controller_state
def copy_controls(obj_to: SimpleControllerState, obj_from: SimpleControllerState): """Copies the attribute of one SimpleControlerStates to another""" obj_to.steer = obj_from.steer obj_to.throttle = obj_from.throttle obj_to.pitch = obj_from.pitch obj_to.yaw = obj_from.yaw obj_to.roll = obj_from.roll obj_to.jump = obj_from.jump obj_to.boost = obj_from.boost obj_to.handbrake = obj_from.handbrake obj_to.use_item = obj_from.use_item
def finalize_output(output): framework_output = SimpleControllerState() framework_output.throttle = output.throttle framework_output.steer = output.steer framework_output.yaw = output.yaw framework_output.pitch = output.pitch framework_output.roll = output.roll framework_output.boost = output.boost framework_output.handbrake = output.handbrake framework_output.jump = output.jump return framework_output
def get(self, data): c = SimpleControllerState() c.throttle = max(min(data[0], 1), -1) c.steer = max(min(data[1], 1), -1) c.pitch = max(min(data[2], 1), -1) c.yaw = max(min(data[3], 1), -1) c.roll = max(min(data[4], 1), -1) c.jump = data[5] c.boost = data[6] c.handbrake = data[7] c.use_item = data[8] return c
def update(self): controller_state = SimpleControllerState() jump = flipHandler(self.agent, self.flip_obj) if jump: if self.targetCode == 1: controller_state.pitch = -1 controller_state.steer = 0 controller_state.throttle = 1 elif self.targetCode == 0: #print("How can I flip towards a ball when you don't tell me where it is?!?!?!") ball_local = toLocal(self.agent.ball.location, self.agent.me) ball_angle = math.atan2(ball_local.data[1], ball_local.data[0]) #print(ball_angle,math.cos(ball_angle)) controller_state.jump = True controller_state.yaw = math.sin(ball_angle) pitch = -math.cos(ball_angle) #-abs(math.cos(ball_angle)) controller_state.pitch = pitch if pitch > 0: controller_state.throttle = -1 else: controller_state.throttle = 1 elif self.targetCode == 2: controller_state.pitch = 0 controller_state.steer = 0 controller_state.yaw = 0 if self.targetCode == 3: controller_state.pitch = 1 controller_state.steer = 0 controller_state.throttle = -1 controller_state.jump = jump controller_state.boost = False #controller_state.throttle = 1 if self.flip_obj.flipDone: self.active = False return controller_state
def get_output(self): output = SimpleControllerState() output.throttle = self.throttle output.steer = self.steer output.pitch = self.pitch output.yaw = self.yaw output.roll = self.roll output.jump = self.jump output.boost = self.boost output.handbrake = self.handbrake return output
def array_to_scs(a): scs = SimpleControllerState() scs.throttle = a[0] scs.steer = a[1] scs.pitch = a[2] scs.yaw = a[3] scs.roll = a[4] scs.jump = a[5] scs.boost = a[6] scs.handbrake = a[7] return scs
def nn_to_rlbot_controls(nn_controls): controller_state = SimpleControllerState() # steering if nn_controls[0] == 1: controller_state.steer = -1.0 elif nn_controls[1] == 1: controller_state.steer = 1.0 else: controller_state.steer = 0.0 # pitch if nn_controls[2] == 1: controller_state.pitch = -1.0 elif nn_controls[3] == 1: controller_state.pitch = 1.0 else: controller_state.pitch = 0.0 # throttle if nn_controls[4] == 1: controller_state.throttle = 1.0 elif nn_controls[5] == 1: controller_state.throttle = -1.0 else: controller_state.throttle = 0.0 controller_state.jump = (nn_controls[6] == 1) controller_state.boost = (nn_controls[7] == 1) controller_state.handbrake = (nn_controls[8] == 1) if controller_state.handbrake: controller_state.roll = controller_state.steer controller_state.yaw = 0.0 else: controller_state.roll = 0.0 controller_state.yaw = controller_state.steer return controller_state
def calcController(agent, target_object, target_speed): goal_local = toLocal([0, -sign(agent.team)*FIELD_LENGTH/2, 100], agent.me) goal_angle = math.atan2(goal_local.data[1], goal_local.data[0]) loc = toLocal(target_object, agent.me) controller_state = SimpleControllerState() angle_to_targ = math.atan2(loc.data[1],loc.data[0]) current_speed = velocity2D(agent.me) distance = distance2D(target_object, agent.me) #steering controller_state.steer = steer(angle_to_targ) r = radius(current_speed) slowdown = (Vector3([0,sign(target_object.data[0])*(r+40),0])-loc.flatten()).magnitude() / cap(r*1.5,1,1200) target_speed = cap(current_speed*slowdown,0,current_speed) # throttle if agent.ball.location.data[0] == 0 and agent.ball.location.data[1] == 0: controller_state.throttle, controller_state.boost = 1, True else: controller_state.throttle, controller_state.boost = throttle(target_speed,current_speed) #dodging time_diff = time.time() - agent.start if (time_diff > 2.2 and distance <= 150) or (time_diff > 4 and distance >= 1000) and not kickoff(agent): agent.start = time.time() elif time_diff <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_diff >= 0.1 and time_diff <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_diff > 0.15 and time_diff < 1: controller_state.jump = True controller_state.yaw = math.sin(goal_angle) controller_state.pitch = -abs(math.cos(goal_angle)) if not dodging(agent) and not agent.me.grounded: target = agent.me.velocity.normalize() targ_local = to_local(target.scale(500), agent.me) return recoveryController(agent, targ_local) return controller_state
def shotController(self, agent): controller_state = SimpleControllerState() goal_location = toLocal( [0, -sign(agent.team) * FIELD_LENGTH / 2, 0], agent.me) #100 is arbitrary since math is in 2D still goal_angle = np.arctan2(goal_location[1], goal_location[0]) #print(goal_angle * 180 / np.pi) location = toLocal(agent.ball, agent.me) angle_to_target = np.arctan2(location[1], location[0]) target_speed = velocity2D( agent.ball) + (distance2D(agent.ball, agent.me) / 1.5) current_speed = velocity2D(agent.me) #steering if angle_to_target > .1: controller_state.steer = controller_state.yaw = 1 elif angle_to_target < -.1: controller_state.steer = controller_state.yaw = -1 else: controller_state.steer = controller_state.yaw = 0 #throttle if angle_to_target >= 1.4: target_speed -= 1400 else: if (target_speed > 1400 and target_speed > current_speed and agent.start > 2.2 and current_speed < 2250): controller_state.boost = True if target_speed > current_speed: controller_state.throttle = 1.0 elif target_speed < current_speed: controller_state.throttle = 1 #dodging time_difference = time.time() - agent.start if time_difference > 2.2 and distance2D(agent.ball, agent.me) <= 270: agent.start = time.time() elif time_difference <= .1: controller_state.jump = True controller_state.pitch = -1 elif time_difference >= .1 and time_difference <= .15: controller_state.jump = False controller_state.pitch = -1 elif time_difference > .15 and time_difference < 1: controller_state.jump = True controller_state.yaw = math.sin(goal_angle) controller_state.pitch = -abs(math.cos(goal_angle)) return controller_state
def follow_controller(agent, target_object, target_speed): location = toLocal(target_object, agent.me) controller_state = SimpleControllerState() angle_to_ball = math.atan2(location.data[1], location.data[0]) current_speed = velocity2D(agent.me) pitch = agent.me.location.data[0] % math.pi roll = agent.me.location.data[2] % math.pi # Turn dem wheels controller_state.steer = cap(angle_to_ball * 5, -1, 1) print(velocity2D(agent.me)) if abs(angle_to_ball) > (math.pi / 3.): controller_state.handbrake = True else: controller_state.handbrake = False # throttle if target_speed > current_speed: controller_state.throttle = 1.0 if target_speed > 1400 and agent.start > 2.2 and current_speed < 2250 and abs( angle_to_ball) < (math.pi / 3.): controller_state.boost = True elif target_speed < current_speed: controller_state.throttle = 0 # doging time_difference = time.time() - agent.start if time_difference > 2.2 and distance2D( target_object, agent.me) > 1000 and abs(angle_to_ball) < 1.3 and velocity2D( agent.me) > 1200: agent.start = time.time() elif time_difference <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_difference >= 0.1 and time_difference <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_difference > 0.15 and time_difference < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 # print("target: " + str(target_speed) + ", current: " + str(current_speed)) return controller_state
def get_controls(game_info, sub_state_machine): controls = SimpleControllerState() if game_info.me.rot.yaw > ball_angle: direction = -1 else: direction = 1 if game_info.me.wheel_contact: controls.jump = 1 controls.boost = 1 controls.yaw = direction persistent = game_info.persistent return controls, persistent
def goto(target_location, target_speed, my_car, agent, packet): car_speed = Vec3(my_car.physics.velocity).length() distance = Vec3(my_car.physics.location).flat().dist( target_location.flat()) angle = Orientation( my_car.physics.rotation).forward.ang_to(target_location - Vec3(my_car.physics.location)) controls = SimpleControllerState() controls.steer = steer_toward_target(my_car, target_location, 0) controls.yaw = steer_toward_target(my_car, target_location, -my_car.physics.angular_velocity.z / 6) controls.throttle = cap(target_speed - car_speed, -1, 1) controls.boost = (target_speed > 1410 and abs(target_speed - car_speed) > 20 and angle < 0.3) controls.handbrake = angle > 2.3 controls.jump = (1 if my_car.physics.location.y >= 0 else -1) == ( 1 if agent.team == 1 else -1 ) and abs( my_car.physics.location.y) > 5000 and my_car.physics.location.z > 200 controls.use_item = Vec3(my_car.physics.location).dist( Vec3(packet.game_ball.physics.location)) < 200 and relative_location( Vec3(my_car.physics.location), Orientation( my_car.physics.rotation), Vec3(packet.game_ball.physics.location)).z < 75 if (abs(target_speed - car_speed) > 20 and angle < 0.3 and distance > 600) and ((target_speed > 1410 and my_car.boost == 0) or 700 < car_speed < 800): agent.stack.append(wavedash(target_location)) return controls