def check_facing(self, position=None): """check_facing(position=None) position: an Opioid vector Turn the object toward position. If None, use obj.position""" if not self.enabled: self.action.abort() return if position is None: if not self.target: return obj = get_gnamed_object(self.target) if not obj: return position = obj.position target_angle = angle_to(self.owner.position, position) + self.offset if self.rotation_speed < 0: # set owner to proper rotation instantly self.owner.rotation = target_angle else: if self.target_angle != target_angle: #create an action that will rotate owner to proper angle if self.action: self.action.abort() self.action = (RotateTo(target_angle, speed=self.rotation_speed) + \ self.end_action).do(self.owner) self.target_angle = target_angle if self.owner.rotation == self.target_angle: self.target_reached()
def face_motion(self): if not self.enabled: self.last_position=None return if self.last_position and tuple(self.owner.position)\ != self.last_position: self.owner.rotation = angle_to( self.last_position, self.owner.position) self.last_position = tuple(self.owner.position)
def face_motion(self): if not self.enabled: self.last_position = None return if self.last_position and tuple(self.owner.position)\ != self.last_position: self.owner.rotation = angle_to(self.last_position, self.owner.position) self.last_position = tuple(self.owner.position)
def on_rotate(self, handle): mouse_pos = Mouse.get_position() angle = angle_to(self.node.position, mouse_pos) new_rotation = self.orig_rot + angle - self.orig_angle if is_shift_down(): new_rotation = round(new_rotation / 15.0) * 15 new_rotation = round(new_rotation, 1) self.node.rotation = new_rotation handle.position = (0, 0) self.surround_node(force=True)
def follow(self): if not self.enabled: return owner = self.owner try: mousepos = owner.layer.convert_pos(Mouse.position[0], Mouse.position[1]) # convert from Opioid2D.Vector to simple co-ordinates my_pos = (owner.position[0], owner.position[1]) mousepos = (mousepos[0], mousepos[1]) if my_pos != mousepos: if self.face_movement: owner.rotation = angle_to(my_pos, mousepos) owner.position = mousepos except: # stopping the scene in the middle of this can cause problems return
def on_rotate_begin(self, handle): self.orig_rot = self.node.rotation mouse_pos = Mouse.get_position() self.orig_angle = angle_to(self.node.position, mouse_pos)