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] My Pygame Sprite not appearing... noodlespinbot 3 5,032 Oct-30-2020, 06:51 AM
Last Post: robinmurphy
  My Pygame Sprite not appearing... noodlespinbot 1 2,943 Apr-08-2020, 11:25 AM
Last Post: pyzyx3qwerty
  [PyGame] pygame, help with making a function to detect collision between player and enemy. Kris1996 3 4,790 Mar-07-2020, 12:32 PM
Last Post: Kris1996
  [PyGame] Terrible Sprite controls, need help. michael1789 16 8,448 Dec-18-2019, 10:32 PM
Last Post: michael1789
  [PyGame] Sprite image.get_rect() moves sprite to 0, 0 michael1789 2 5,897 Dec-13-2019, 08:37 PM
Last Post: michael1789
  How to place walls in random dungeon ? michael1789 5 5,452 Nov-11-2019, 12:12 AM
Last Post: michael1789
  Pygame sprite not moving michael1789 1 3,994 Nov-10-2019, 03:54 AM
Last Post: michael1789
  Sprite not rendering Clunk_Head 2 3,620 Oct-03-2019, 11:27 AM
Last Post: Clunk_Head
  Need help making a sprite GalaxyCoyote 4 4,427 Aug-11-2019, 09:12 PM
Last Post: metulburr
  creating sprite mask pfaber11 5 5,058 Jun-12-2019, 09:39 PM
Last Post: pfaber11

Forum Jump:

User Panel Messages

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