Physics – Unity RigidBody does not bounce as expected in low impact collisions

I have a Rigidbody2D with a CircleCollider2D, on which I show a sprite of a circle. This rigid body can be "shot" in my game.

I also have 4 rectangular BoxCollider2Ds on the edges of the game screen.

When I shoot the circle, it bounces off the rectangular collider well, except in cases where the velocity of impact perpendicular to the surface of the rectangular collider is very slow. In this case the rebound speed in this direction is somehow zero.

Here is the RigidBody2D and CircleCollider2D setup of the circle:

Enter image description here

Here is the BoxCollider2D of the rectangular collider:

Enter image description here

The material "New Physics Material 2D" attached to the ball and the box colliders has the friction at 0 and the bounce at 1:

Enter image description here

Here are two gifs, the first showing how it works (correctly) in most cases, and the second showing what happens in a low speed impact. The "choppy" nature of these gifs is due to their "giffy" nature. In my game, the movement is smooth.

Enter image description here

Enter image description here

I wonder why the ball doesn't bounce back in a low-speed impact the same way it does in a high-speed impact (i.e., through the angle of exit = angle of entry).

Collision detection – collisions with rock and player (spaceship)

I try to do when the stone hits the spaceship or player that it should decrease health from the health bar, but when I run it it doesn't work. The stone randomly reduces health. How can I fix it?

# 1 - Import library
import pygame
from pygame.locals import *
import math
import random
# 2 - Initialize the game
pygame.display.set_caption('Rescue Mission!')
clock = pygame.time.Clock()
width, height = 840, 680
screen=pygame.display.set_mode((width, height))
keys = (False, False, False, False)
lifeboostertimer= 200

# 3 - getting images from files 
player = pygame.image.load('spaceship.png')
background = pygame.image.load("background.png")
background = pygame.transform.scale(background, (840, 680))
laserbeam = pygame.image.load("laserbeam2.png")
rockpic1 = pygame.image.load("ro.png")
healthbar = pygame.image.load("healthbar.png")
health = pygame.image.load("health.png")
lifeboost = pygame.image.load("lifeboost.png")
lifeboost1 = lifeboost

# 4 - keep looping through
while 1:
    # 5 - clear the screen before drawing it again

    # 6 - putting the images of the game on screen

    #screen.blit(lifeboost, (100,100))

    position = pygame.mouse.get_pos()
    angle = math.atan2(position(1)-(playerpos(1)+32),position(0)-(playerpos(0)+26))
    playerrot = pygame.transform.rotate(player, 360-angle*57.29)
    playerpos1 = (playerpos(0)-playerrot.get_rect().width/2, playerpos(1)-playerrot.get_rect().height/2)
    screen.blit(playerrot, playerpos1)

    for bullet in laserbeams:
        if bullet(1)<-64 or bullet(1)>840 or bullet(2)<-64 or bullet(2)>680:
        for projectile in laserbeams:
            laserbeam1 = pygame.transform.rotate(laserbeam, 360-projectile(0)*57.29)
            screen.blit(laserbeam1, (projectile(1), projectile(2)))
    # Draw Rocks
    if objecttimer==0:
        rocks.append((840, random.randint(50,430)))
        if objecttimer1>=35:
    for rock in rocks:
        if rock(0)<-1:
        # - Attack castle(change to Attack spaceship later on)
        playerrect = pygame.Rect(player.get_rect)

        if rockrect.colliderect(playerrect):
            healthvalue -= random.randint(5,20)

        # Check for collisions
        for bullet in laserbeams:

            if rockrect.colliderect(bullrect):


        index += 1

    # Next Rock

    #for rock in rocks:

    # Draw 1-UP image
    if lifeboostertimer==0:
        lifebooster.append((840, random.randint(50,430)))

        if lifeboostertimer1>=15:


    # Makes object move
    for lifeboost in lifebooster:
        if lifeboost(0)<-1:
        #speed of 1-UP


        #if lifeboosterrect.left<1:
            #healthvalue += random.randint(5,20)

        # Check for collisions (if hit for lifebooster give more health)


        for bullet in laserbeams:

            if lifeboosterrect.colliderect(bullrect):
                print ("rock poped")
                healthvalue += random.randint(5,20)

   # - Next 1-UP image
    #index2+=1   #can probably take this line and next line out
    #for lifeboost in lifebooster:
    for rock in rocks:

    # 6.4 - Draw clock
    font = pygame.font.Font(None, 24)
    survivedtext = font.render(str((90000-pygame.time.get_ticks())/60000)+":"+str((90000-pygame.time.get_ticks())/1000%60).zfill(2), True, (0,0,0))
    textRect = survivedtext.get_rect()
    screen.blit(survivedtext, textRect)

    # 6.5 - Draw health bar
    screen.blit(healthbar, (5,5))
    for health1 in range(healthvalue):
        screen.blit(health, (health1+8,8))

    # 7 - update the screen
    # 8 - loop through the events
    for event in pygame.event.get():
        #print (event)
        # check if the event is the X button 
        if event.type==pygame.QUIT:

           # if it is quit the game
        if event.type == pygame.KEYDOWN:
            if event.key==K_UP:

            elif event.key==K_LEFT:

            elif event.key==K_DOWN:

            elif event.key==K_RIGHT:
        if event.type == pygame.KEYUP:
            if event.key==pygame.K_UP:
            elif event.key==pygame.K_LEFT:
            elif event.key==pygame.K_DOWN:
            elif event.key==pygame.K_RIGHT:
        if event.type==pygame.MOUSEBUTTONDOWN:

    # 9 - Move player
    if keys(0):
    elif keys(2):
    if keys(1):
    elif keys(3):

java – How can Box2D best manage collisions at different (simulated) heights?

I'm working on a 2D top down game, but we're also using a Z coordinate. This simulates the effect of 3D / height. Now the player can walk under and over a bridge. The next thing I did was manage the collision at these different heights. I managed to get the player to collide with the edge of the bridge when he walks over it, but when he walks under it he doesn't collide. But I'm not sure I did it right.

As I am doing it, I use different bits for different heights:

public static final short ENTITY_Z0_BIT = 1;
public static final short ENTITY_Z1_BIT = 2;
public static final short ENTITY_Z2_BIT = 4;
public static final short COLLISION_Z0_BIT = 8;
public static final short COLLISION_Z1_BIT = 16;
public static final short COLLISION_Z2_BIT = 32;

And then a collision body in Z 1 (or on the second floor) has the following filter:

fixtureDef.filter.categoryBits = COLLISION_Z1_BIT;
fixtureDef.filter.maskBits = ENTITY_Z1_BIT;
fixtureDef.filter.groupIndex = (short) 0;

This means that the wall on the second floor only collides with an entity on the second floor, since I also change the filter of the entity depending on whether its Z coordinate increases / decreases. This means that I need to add more bits if I need a higher simulated Z-axis, and that doesn't allow dynamic Z-axis machining either, because I do a large switch case or if statement for each Z-axis and then adjust the filter accordingly.

My second option was to set the groupIndex to be identical to the Z axis + 1 of the collision / entity. If a collision body and an entity body both have groupIndex 1, they ALWAYS collide. However, if the object moves up on the Z axis, its groupIndex is set to 2 and no longer collides. This also seemed like a nice and dynamic idea. But then everything that has to collide with a wall or an object automatically collides with all other bodies that need the same groupIndex for the same reason. This doesn't allow for much flexibility.

Which of these two options is the best? And if there is another better way, let me know!

ab testing – How important is it to avoid A / B test collisions?

Suppose you have 3 A / B tests as such

  1. Control against A
  2. Control against B
  3. Control against C

Unless you specifically ensure that the tests do not collide (run on top of each other), users with A + B, B + C, A + B + C are displayed.

Technically speaking, if you look at the results of Experiment 1, both Control and A are found to have the same number of contaminants 2 and 3, so the only difference in performance between 1 and A should only be the effects of A. ,

Thoughts? Is it always a good idea to avoid collisions, or can we just assume that we are good as long as the pollution is evenly distributed?

Fix collisions after the first collision

How can we check collisions in a sweep test for a beam after the first collision has been detected and the beam has been deflected?

Physics system steps are:

  1. Update the speeds (gravity, etc.)
  2. Fix collisions
    • The jet cuts the ground and is moved back with the penetration depth.
    • The new speed is calculated as a reflection
  3. Update positions
    • The beam is now on the wrong side of the wall
      This all happens in 1 frame

When the orange beam hits the ground just before the wall, the beam is tunneled through the wall at the new speed within a frame.
The naive way to fix this is to recheck all bodies at the new speed after each collision. However, this can take several iterations as the beam jumps around in a corner. There is no way to know how many times the beam has to be processed.

What would be a good way to fix this problem?

Pinboard is overlooked in 1 frame

Algorithms – How can I create 10-digit, unique codes without collisions, but without being predictable?

If we use numbers and letters, there are 36 ^ 10 unique combinations. A collision is already unlikely, but I have to make it impossible, so the use of hashing is out of the picture (?).

The use case is that users each redeem when they have been "redeemed" as being redeemable. Think like Webkinz codes.

An inefficient solution would be to generate all at once, to have a property for each one indicating whether it has been activated or not, and to keep a pool of those who have been redeemed and those who have not.

It annoys me to keep a database of 36 ^ 10 codes just because I can not find a clever algorithm. That's why I'm here to help you.

Any ideas?

Unity – 3D Collisions – When I walk under a slope, I push myself through the ground

Here is a really short video (less than 30 years) of this issue:

If I move the player towards the slope (the player is below), he pushes the player into the floor collider instead of blocking it.

I searched the internet for a while, but found nothing about it

Do you have something in mind?
Thanks for your time

Info: I move the player with rigidbody.MovePosition()

The collision of the player is a capsule.

c ++ – How to Add 3D Collisions to the Ember Game

Hey guys, I want to add 3D collisions to my game. But I do not want to use a physics library, they are so complex. I tried to write something like that, but it does not work as expected:

void collidek(int x,int y,int z, bool scfw = 1) {

    if (x > 3) {
        scfw = 0;

    if(x < 3) {

        scfw = 1;
        if (scfw = true){
            x-= 5.0f;

    if (z > 3) {
        scfw = 0;



So I do not know Alegebra my Alegebra is really low.

I want the ultrashort collision detection to be flawed, not only do I want collision detection to work.

Please do not say a useful comment, for example, you will learn some Alegebra like this.

Please specify only the code. I needed a very basic collision detection. I'm wondering that this is an AABB collision system that uses a maximum of 20 lines of code and is readable.

Many thanks…

Time step – dealing with collisions in grid-based games (Snake)

I try to integrate gentle movements into my snake game. So far, everything works well, except when it comes to colliding with edges. Basically, there is no time for a change, I do not know how to explain it better.

void UpdateSnake(Snake *snake, float timeStep)
    float f = CalculateTime(snake->head->position.x, snake->head->position.y, timeStep);

    snake->head->position.x += (snakeSpeed * fabs(f) * direction.x);
    snake->head->position.y += (snakeSpeed * fabs(f) * direction.y);

timeStep = (1.0f / 60.0f) * 1000.0f (ms)
snakeSpeed ​​= 0.5

Algorithm: When turning (so that the key is pressed) I calculate the time needed to get to the nearest grid point if there is room for another step f = time step, otherwise f is this time.

Snake Repository
Everything is in Game.c and GameObjects.c

Physics – Where and how should I look for collisions in multiplayer?

I'm doing a multiplayer game. At the moment I've added a script to towers and I have Boolean values ​​that need to be changed with OnTriggerEnter.

When triggered, the client sends a message to the server and the status of the towers decreases. Thats how it works.

However, I do not know if using OnTriggerEnter is safe as the calculation is done on the client side. Should I expect server side? And how do I do that? (Using Physics.ComputePenetration is a bit slow.)