PVectors in Class Objects

My apologies, I just learned that I should have formatted the code to make it easier to run.

targ_pos = PVector(100, 300, 0)
mis_pos = PVector(400, 600, 0)
l_o_s = PVector()

class Foo:
    def __init__(self, targ_pos, mis_pos):
        self.targ_pos = targ_pos
        self.mis_pos = mis_pos
        self.l_o_s = PVector()
    def sub_vec(self, targ_pos):
        # temp_vec = mis_pos.copy() # uncomment to clear error
        # self.l_o_s = temp_vec.sub(self.targ_pos) # uncomment to clear error
        self.l_o_s = self.mis_pos.sub(self.targ_pos) # comment to clear error
        return self.l_o_s

foo = Foo(targ_pos, mis_pos)
i = 1    

def draw():
    global i
    vec = foo.sub_vec(targ_pos)
    print('targ_pos ', targ_pos)
    print('mis_pos ', mis_pos)
    print('vec ', vec)
    if i == 2:
        noLoop()
    i += 1

Mike

2 Likes