Python Forum
[PyGame] Making Player Sprite Ricochet of walls
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Making Player Sprite Ricochet of walls
#5
Here. I try to explain it better.
Displacement collision. Moving Object hit a Stationary Object.
1. get the clipping rect size
width, height = object.rect.clip(collision.rect).size
2. Determine the Axis.
if width < height:
    # X Axis
else:
    # Y Axis
3. Determine which side. Displace object and Change direction.
# Determine Axis X or Y
if width < height:
    # X Axis
    # Determine which side
    if object.rect.centerx > collision.rect.centerx:
        # Displace object
        object.rect.left = collision.rect.right
    else:
        # Displace object
        object.rect.right = collision.rect.left

    # Change direction
    object.direction.x = -object.direction.x
else:
    # Y Axis
    # ...
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
RE: Making Player Sprite Ricochet of walls - by Windspar - Jun-03-2019, 10:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] pygame, help with making a function to detect collision between player and enemy. Kris1996 3 3,284 Mar-07-2020, 12:32 PM
Last Post: Kris1996
  [PyGame] Sprite image.get_rect() moves sprite to 0, 0 michael1789 2 4,552 Dec-13-2019, 08:37 PM
Last Post: michael1789
  How to place walls in random dungeon ? michael1789 5 3,963 Nov-11-2019, 12:12 AM
Last Post: michael1789
  Sprite not rendering Clunk_Head 2 2,095 Oct-03-2019, 11:27 AM
Last Post: Clunk_Head
  Need help making a sprite GalaxyCoyote 4 3,190 Aug-11-2019, 09:12 PM
Last Post: metulburr
  moving a sprite pfaber11 3 2,548 May-15-2019, 12:52 PM
Last Post: pfaber11
  Raycasting(again) walls with different heights robie972003 0 2,434 Mar-23-2019, 01:18 AM
Last Post: robie972003
  [PyGame] Need Help With Sprite ghost0fkarma 2 3,253 Jan-09-2018, 02:14 PM
Last Post: ghost0fkarma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020