Skip to content

Commit

Permalink
fixed collision
Browse files Browse the repository at this point in the history
  • Loading branch information
drwuro committed Jan 28, 2024
1 parent 7879ad9 commit 6eb4e94
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Feather.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,23 @@ def update_phys(self, dt, fluid):

def updatePosition(self, dt):
potential_pos = self.pos + self.v * dt
nbr_wall = self.detectWall(potential_pos)

# NOTE TO FUTURE SELF: ALWAYS CHECK HORIZ/VERT SEPERATELY!!

# horizontal check
nbr_wall = self.detectWall((potential_pos[0], self.pos[1]))
if nbr_wall is not None:
if nbr_wall[0] != 0: # left/right wall
self.v[0] = -self.v[0] /10 # fudge v to not get stuck in wall

# vertical check
nbr_wall = self.detectWall((self.pos[0], potential_pos[1]))
if nbr_wall is not None:
if nbr_wall[1] != 0: # top/bottom wall
self.v[1] = -self.v[1] /10 # fudge v to not get stuck in wall

corrected_pos = self.pos + self.v * dt
self.pos = corrected_pos
else:
self.pos = potential_pos
corrected_pos = self.pos + self.v * dt
self.pos = corrected_pos

def render(self, screen):
feather = self.feather_sprites[self.anim_cnt]
Expand All @@ -85,12 +91,12 @@ def getBoundingBox(self, pos=None):

def detectWall(self, potential_pos):

# 1 3
# 0 2
# o----o
# | |
# | |
# o----o
# 2 4
# 1 3

collision_point = np.copy(potential_pos)
bbox = self.getBoundingBox(collision_point)
Expand Down

0 comments on commit 6eb4e94

Please sign in to comment.