networking – Multiplayer tile based movement collisions cause client prediction to fail

I am developing a tile-based online multiplayer game, but I am stuck. Players can move across the grid in the four cardinal directions, as can enemies, but two players/enemies cannot occupy the same tile at the same time. Positions of all players/enemies are synced for all clients.

My current implementation of movement: Clients send a ‘request to move’ to the server whenever they are stationary on a tile.

I have implemented client prediction. When a button is pressed to move, the client shows their character immediately moving in that direction, as opposed to waiting for confirmation from the server, preventing lag between player input and visible results.

The issue arises when the player attempts to move to a position that will soon be occupied. For example, the player presses up when an enemy is very close to entering the tile above the player (though they can’t currently know that the enemy will choose that tile next). Locally this is confirmed and the upwards animation begins, but by the time the request to move up arrives at the server, the tile is no longer free, and the player is not moved up on the server.

This creates a situation where the player’s local position is out of sync with that of the server. My current solution to this is snapping the local player back to the server’s position when this happens, but this looks awful. It seems to be happening a lot, making the game nearly unplayable.

Is there a way around this?
Any help would be very much appreciated, thanks.

Some other notes: I send updates from the server 10 times a second, which consist of every object’s position (and other stuff). When a movement event is processed, the object’s position is updated immediately, even though an animation follows.

separating axis theorem – SAT Collisions: Resolving rotations

Currently I have a working 2D SAT collision system with only boxes, but works with static rotations as well, leaving room for triangles. One of the issues I’ve been able to resolve was tunnelling, thanks to this thread’s psuedocode that I got working for myself.

Problem is, this doesn’t support moving rotations like a system using a minimum-translation-vector. If I rotate alongside the side of an object, the system will fail even if I’m not moving.

My first thought in solving this was to use the longest line you can draw in a square (that being the points on either side of a square) and comparing the length of that to whatever side on any axis, but even squares have different sizes on any given rotation projected onto an axis.

The system also doesn’t work with multiple objects, because – while you can use the algorithm on a group of objects and find the shortest distance out of all of them – if I conserve my velocity relative to the colliding axis, diving into the crest of 2 objects means I will phase through one of them not beyond a 45 degree angle.

Is there an effective way to resolve collisions on rotations and groups of objects, while using this anti-tunnelling algorithm? I don’t care if it’s expensive, I’ll take whatever you can think of.

Unity – How can collisions between objects occur with the same script?

I try to have cars on the street. The cars have a trigger at the front and a hit box at the back. What I want to do is when the trigger hits the hit box, it compares the variables for the speed of the two cars in the collision, i.e. H. The car in the back slows down or corresponds to the speed of the car in front. However, I have problems determining and comparing the speed of both cars. This is because both prefabs were created using the same script. What I learn means that I am only referring to the same script and not to the actual values ​​of the individual car. But how could I get around this? Is it possible for collisions between objects to occur with the same script?

private void OnTriggerStay2D(Collider2D collision)
{
    Debug.Log("TriggerStay");

    Traffic Col_speed = collision.gameObject.GetComponent();

    if (speed > Col_speed.speed)
    {
        Accelerate = false;
        ApplyBreak = true;
    }
    else if (speed< Col_speed.speed)
    {
        Accelerate = false;
        ApplyBreak = false;
        speed = Col_speed.speed;
    }
}

Unit – Collisions work in the editor, but not when compiling

This has been asked a few times, but none of the answers worked; The other questions are also very old. I have an object with a mesh collider on it. The collisions work perfectly in the editor. However, there are no collisions at all in the compiled game. It is important to note that other colliders (box colliders, sphere colliders, etc.) work perfectly both in the compiled game and in the editor.

The network is the following:
Enter the image description here

What I tried:

  • Rebuilding the entire prefabricated house with the Collider.
  • Recreate the mesh for the mesh collider.
  • Use a different format for the network (.fbx, .obj, etc.)

Additional details:
– The object has a rigid body and a convex mesh collider.

  • The object is moved by script at the speed of the rigid body.

  • It used to work flawlessly until I reduced everything in the scene by a factor of two. So I opened Blender to half the size of the net. Regardless, the problem is not the network, but the fact that it works in the editor and only in the editor.

How often should I look for collisions in a Miinecraft-like game?

I'm trying to create a game from scratch in Dart, much like Minecraft.

As far as I understand, there are two main functions in a general game loop:

  • tick: A function that runs a specified number of times per second regardless of the frame rate. And I think in Minecraft these are called TPS (tick per second).

  • Render: A function that draws everything on the screen and is referred to as every image. The frequency depends on the functions of the device. (FPS)

(I'm referring to Minecraft as it's a well known and fairly simple game.)

I'm trying to understand when collisions should be checked. Are they checked every time the screen is drawn (rendered) or when the tick function is executed?

SQL Server – hash matches with collisions

I try to improve certain matches that often occur in many, many dimension columns. As I understand it, my decisions are:

  1. Match in many columns
  2. Hash the columns, save the hash, match it.

If I use something like "checksum", is there a known algorithm to handle the collisions?
So the match would work like this:

  1. Combine two tables where checksum Hashes match.
  2. If more than one row is returned, filter the results by specifying all dark columns

Everyone tried it checksum Make hashes faster on a large number of columns?

I should say I'm looking for a SQL / TSQL solution. I can easily achieve this match using Python or C #

Hash – primary clusting when resolving linear probing collisions: there can only be one cluster / block, right?

I believe that primary clustering is a problem with the linear probing method of hash collision resolution. However, the description gives the impression that there can be several clusters of connected blocks. I thought there could possibly be only one block since the linear check goes through all the addresses one after the other.

Path finding – box collisions between vehicles in traffic pattern

I am working on a traffic simulator. At the moment I have options to manage 4-way stops and a solution to efficiently determine which vehicles are colliding with each other. All vehicles work independently of one another and overlap / ignore all vehicles they pass.

I want to find a way to resolve collisions between vehicles so that a Vehicle will follow that Vehicle in front. When a Vehicle stops at an intersection Vehicles the ones that follow should also stop and wait.

The relevant components that I have already implemented are listed below:

  • TileGrid with road segments.
  • TravelGraph Waypoints diagram for Vehicles along the trips TileGrid,
  • CollisionTracker to efficiently determine which vehicles collide, d. H. search for O (1) get_collisions() -> List()
  • Intersection to determine which vehicles are waiting at an intersection and which ones Vehicles it can happen.

The only seemingly practical algorithm is currently:

  1. Calculate the speed and position of all vehicles after the check mark
  2. Determine which vehicles are in a collision
  3. Determine which vehicles are in a "collision group" (e.g. if A collides with B, collides with C, then (A, B, C) are in a group).
  4. Determine the order of vehicles in each group based on their speeds (e.g. when A, B and C move to the right and C is on the far right, followed by B followed by A, the order is (C, B,) . ON)).
  5. Recalculate the positions of all vehicles in the order from front to back (e.g. C, B, A) so that they are next to the vehicle but do not touch it Vehicle in front of them.

Problems with this solution:

  • This requires many recalculations. If there is a line from n I would effectively calculate 2 * vehicles that are waiting for a lightn Items per tick in addition to all other overheads for setting up groups, orders, etc.
  • If the vehicles follow each other in a curve, the logic for determining the "vehicle order" becomes more complex and increases the calculations per tick.

Ideally, moving the vehicles would require n Calculations per tick.

I am open to any suggestions here. I tried to make my code as modular as possible, so I like to rewrite large parts of it if there is a better architecture to solve this problem.


Below is the visual representation of the TileGrid (black), TileGraph (purple) and Vehicles (circles).

Enter the image description here

Python – Pygame Multiple collisions between two objects

Ok so I tried to figure out how to set it up and I can't get it to work properly. I'm trying to get the functionality that resembles the moving logs in Frogger game if you're familiar with it. So far, what I have has worked with collision detection for just one pygame.sprite.Group ()

import pygame
import os
import random

os.environ('SDL_VIDEO_CENTERED') = '1'

WIDTH = 480
HEIGHT = 720
FPS = 60

# Moving Object spacing setup first row 
INSTANCE_COUNT = 0
BOX_WIDTH = 30
SPACING = 120

# object speed
pos_objspeed = 1
neg_objspeed = -1

BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)

pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()

class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((30, 30))
        self.image.fill(GREEN)
        self.rect = self.image.get_rect()
        self.rect.centerx = WIDTH / 2
        self.rect.bottom = HEIGHT - 96
        self.speedx = 0
        self.speedy = 0

class MovingObj_Test(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((90, 30))
        self.image.fill(RED)
        self.rect = self.image.get_rect()
        self.rect.x = (INSTANCE_COUNT * (SPACING+ BOX_WIDTH))
        #self.rect.x = random.randrange(WIDTH)
        self.rect.bottom = 384
        self.speedx = pos_objspeed

    def update(self):
        self.rect.x += self.speedx
        if self.rect.x >= 480:
            self.rect.x = -30
            self.rect.bottom = 384
            self.speedx = pos_objspeed        

class MovingObj_TestTwo(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((90, 30))
        self.image.fill(RED)
        self.rect = self.image.get_rect()
        self.rect.x = (INSTANCE_COUNT * (SPACING+ BOX_WIDTH))
        #self.rect.x = random.randrange(WIDTH)
        self.rect.bottom = 336
        self.speedx = neg_objspeed

    def update(self):
        self.rect.x += self.speedx
        if self.rect.x >= 480:
            self.rect.x = -30
            self.rect.bottom = 336
            self.speedx = neg_objspeed

all_sprites = pygame.sprite.Group()
movingobj_l = pygame.sprite.Group()
movingobj_r = pygame.sprite.Group()

for i in range (3):
    INSTANCE_COUNT = i + 1
    obj1 = MovingObj_Test()
    all_sprites.add(obj1)
    movingobj_l.add(obj1)

for i in range (3):
    INSTANCE_COUNT = i + 1
    obj2 = MovingObj_TestTwo()
    all_sprites.add(obj2)
    movingobj_r.add(obj2)

player = Player()
all_sprites.add(player)

running = True
onLogLeft = False
onLogRight = False
groundSpd = 48
while running:

    clock.tick(FPS)

    hitsleft = pygame.sprite.spritecollide(player, movingobj_l, False, pygame.sprite.collide_rect)
    for hit in hitsleft:
        player.speedx = pos_objspeed
        player.speedy = 0
        onLogLeft = True
    if len(hitsleft) == 0:
        onLogLeft = False
        player.speedx = 0
        player.speedy = 0
    hitsright = pygame.sprite.spritecollide(player, movingobj_r, False, pygame.sprite.collide_rect)
    for hit in hitsright:
        player.speedx = neg_objspeed
        player.speedy = 0
        onLogRight = True
    if len(hitsright) == 0:
        onLogRight = False
        player.speedx = 0
        player.speedy = 0


    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                player.speedx = -groundSpd
            if event.key == pygame.K_RIGHT:
                player.speedx = groundSpd
            if event.key == pygame.K_UP:
                player.speedy = -groundSpd
            if event.key == pygame.K_DOWN:
                player.speedy = groundSpd

        if event.type == pygame.KEYUP and onLogLeft == False and onLogRight == False:
            if event.key == pygame.K_LEFT:
                player.speedx = 0
            if event.key == pygame.K_RIGHT:
                player.speedx = 0
            if event.key == pygame.K_UP:
                player.speedy = 0
            if event.key == pygame.K_DOWN:
                player.speedy = 0

    if onLogLeft == False and onLogRight == False and player.rect.bottom <= 384:
        running = False

    player.rect.x += player.speedx
    player.rect.y += player.speedy

    if event.type == pygame.QUIT:
        running = False



    #player.rect.x += player.speedx
    #player.rect.y += player.speedy

    all_sprites.update()
    screen.fill(BLACK)
    all_sprites.draw(screen)
    pygame.display.flip()



pygame.quit()
quit()

Ok so in my code

hitsright = pygame.sprite.spritecollide(player, movingobj_r, False, pygame.sprite.collide_rect)

checks the collision and updates the player's speed as I expected but the

hitsleft = pygame.sprite.spritecollide(player, movingobj_l, False, pygame.sprite.collide_rect)

doesn't do the same.

I am confused why this is so when someone has any ideas. How can I fix the problem so that it works for both?

Game Maker – How do I create a path without collisions regardless of the size of the enemy / grid?

I make a game in which I have a player and enemies who follow the player depending on the distance.

The map has been marked with a grid so that enemies can follow the player. When the player approaches the enemy, the enemy creates a path to the player and ignores the walls (obj_Block).

Code Creation Grid (obj_ADM):

global.grid=mp_grid_create(0,0,celHor,celVer,celLar,celAlt);

mp_grid_add_instances(global.grid,obj_Block,false);

Code creation path (obj_Enemy):

xPlayer=(obj_Player.x div obj_ADM.celLar)*obj_ADM.celLar+obj_ADM.celLar/2;
yPlayer=(obj_Player.y div obj_ADM.celAlt)*obj_ADM.celAlt+obj_ADM.celAlt/2;

if(mp_grid_path(global.grid,caminho,x,y,xPlayer,yPlayer,1)){
    path_start(caminho,velocidade,path_action_stop,false);
}

Enter the image description here

So something similar happens in the picture below:

Enter the image description here

  • Purple square => enemy
  • Black squares => wall

The enemy walks through part of the wall while chasing the player.

This is obviously due to the different size of the grid and the enemy. Because I did a test with the 20×20 enemy and it worked perfectly.

I resized the grid (which creates the path) to 32×32 and it turned out that instead of crossing the wall, the enemy is far from the walls (in some places on the map):

Enter the image description here

I would like to know how to do this so that none of these situations occur. Regardless of the size of the enemy.

Video I made the code: