# Questions tagged [collision]

In collision detection problems, the challenge is to determine when shapes intersect each other.

93 questions
Filter by
Sorted by
Tagged with
39k views

### Overlapping rectangles

I received the following question in a technical interview today (for a devops/SRE position): Write a function which returns true if the two rectangles passed to it as arguments would overlap if ...
4k views

### Bouncing stacking boxes

I'm not sure if it would be better to make the envelope into an extension of the Rectangle constructor. The physics seem a bit dodgy, it works well most of the time, but sometimes the boxes overlap ...
809 views

### Setting the scene for a role-playing game

I made some games in Pygame, but I am still new to making games. I made this RPG game, and this code is just a part of the game. The game executes different Pygame files for different levels of the ...
6k views

### 2D Collision Detection

I wrote this a while ago but wanted to see if I went about it the right way and if my brain is working correctly. I was thinking about these two projects the other day and I recently released the ...
2k views

### 2D tilemap collision method

Is this the optimal method to check for collisions in a 2d-based game? I put together a working demo of 2D collisions here (WSAD to move, orange blocks collide). I currently use the following code ...
290 views

I'm working on a new prototype that is a simple drag and shoot arcade basketball game. For this project I am working with LibGDX and the Box2d physics library. You can play the game here: Play ...
403 views

### Bounding volume hierarchy

I'm building a bounding volume hierarchy in Golang. I can tell my code works because I did some test on it and it gives the same results as the brute force implementation (brute force is to test all ...
8k views

### Line segment to circle collision algorithm

I've written a function (in Python 3) which computes if a line segment (constraint) and a circle (body) collide, and returns the point of intersection (closest point to the centre of the circle): <...
841 views

### Design of physics with Collision Detection using SFML

I found out that in Visual Studio 2012, it is possible to create project of SFML easily with a template. I am not an experienced C# programmer. Hence I wanted to implement a physics component just for ...
349 views

### Artifact collision in plane module

Here's something I tried putting together as I'm learning. Critiques on anything are welcome. There's also a logic bug in the Plane module I can't identify. The long and the short are that it takes ...
377 views

### Finding the nearest polygon

Finding the nearest polygon out of a list of polygons seems to be quite a challenge on performance, due to lack of optimization. Consider the following image: I'll give the concept behind this. The "...
1k views

### Performance of collision detection in a grid

I have fairly simple collision checking and handling Python code which is currently bottlenecking my performance quite a bit. I haven't done too much coding in python and I'm quite sure there's ...
950 views

### Canvas Drawing/Animation

I am trying to learn how to write good, clean, and efficient JavaScript. I consider myself a novice, at best, in JavaScript. Any comments are appreciated. In an effort to become a better JavaScript ...
1k views

### 2D colliding disks in JavaScript (ideal billiard balls)

I am implementing a simulation of colliding disks (ideal 2D billiard balls) in JavaScript. I follow an event-driven algorithm that avoids discretizing time; the algorithm goes as follows at each step:...
859 views

...
121 views

### Kattis “Hitting the Targets” utilizing a polymorphic relashionship

In order to learn C++ I have written a solution to this Kattis "Hitting the Targets" problem Basically the program is to accept some shapes (circles and rectangles) on std in and a set of points and ...
2k views

### Implementation of SAT (Separating axis theorem)

A project I was working on required the usage of the Separating Axis Theorem to detect collisions between two convex polygons in real time. So I implemented a basic class (...
809 views

### Quad Tree and Collision Detection Implementation

I have an implementation of a quad tree and abstract collision detection classes. The code works but looks very ugly, but I don't know what I could change to make it better. The reason I used two ...
140 views

### Orginizing/Optimising my collision detection setup

I'm creating a 2D tile based platformer with AABB (Axis aligned bounding boxes), and it works, I just want to organize and optimize my setup. Here are methods in my player class and entity class that ...
836 views

### Collision Detection in a 2D shooter game

I have the following code that works just fine for collision detection. The only problem is its size and its performance. I'm trying to do it and many other things 60 times per second, which doesn't ...
617 views

### Rectangle-segment collision detection

I am working with C++ and SDL, hoping to create a game later. I am implementing the collision detection between rectangles and segments. I found this (NateS user's solution) about line-rectangle ...
178 views

### Calculate next position and velocity after “bounce”

Intro and code I have the following function that calculates an object's "next" position and velocity (in 1 dimension) given a boundary [0, max]. ...
320 views

### 2D Platformer Collision Detection/Resolution

I am working on a 2D tile based platformer and was hoping to get someone to review my collision detection. I've only included the X collision check since the Y is essentially the same. Any suggestions/...
241 views

### Handling collision on a turn-based 2D game

I have implemented a collision check algorithm that I have created for my game, and the algorithm uses recursion. Now it all works fine, and I thought to myself, what if there was a way to solve this ...
5k views

### Collision-detection for an SDL game

I am working on a simple SDL game in C++. I want to make my collision detection implementation better. Here's the complete project: ...
500 views

### Computing intersections of a Polyline and a line

I wrote a script to compute / interpolate the nodes of a Polyline at a given latitude, input_lat. It works for my purpose but I am wondering if there is a better, ...
1k views

### Slow foreach loop to check for intersect

I'm trying to make a loop where it returns whether or not a rectangle collides and then to which coords the rectangle should move to. I'm calling my function like this: ...
395 views

### Obstacle-avoiding AI

I have made a game in Java that involves two players to fight each other with spaceships. For one player mode, I have programmed a simple AI to avoid allies and asteroids and go straight towards the ...
2k views

### Ping-pong game with JavaScript and Canvas

I have created my first ping-pong game with JavaScript and Canvas. I will be glad if anybody can tell me how to optimize the code and functionality. https://github.com/nikitalarionov/js-pong First ...
181 views

### OBBs intersection improvement for AABBs-OBBs

I'm trying to code some intersection codes for Oriented Bounding Boxes (OBBs) and axis-aligned bounding boxes (AABBs). I have the OBB-OBB intersection using the Separating Axis Theorem (SAT) and I'm ...
280 views

### Platformer with collisions

Today I started to build my first platformer, first time working with collisions and stuff. Now, surprisingly, everything seems to work, but since this is my first time creating a platformer and I'm ...
282 views

### Collision detection method

I think everyone has some code they are embarrassed and not proud of and today I have decided to show mine. I'm not sure how to go about making this more efficient. At the time I was just happy it did ...
500 views

### Collision-checking optimizations

If I'm working in a 2D environment and have hundreds of objects, brute force collision-checking would be out of the question, but would my method below work? For example, let's say I have a ...
356 views

### Collision detection for moving 2D objects

After implementing SAT (separating axis theorem) and not being happy with it only working on stationary shapes, this in theory allowing for fast objects to glitch through others, I came up with this ...
39 views

### Mutable 2d Rect class

So I wrote a 2d rectangle class for use in a 2d pygame based game engine. It uses the vector class from this question, so if you want to test, you need that code too. I want to ask: Does this ...
84 views

### Clone of “Pop the Lock” iPhone Game

As an exercise, I decided to program my own version of the game Pop the Lock for the iPhone. The look and functionality are essentially the same, though the controls are modified for playing on a ...
200 views

Old code ...
234 views

### 2D Game - Ray-cast collision handling

This code is an excerpt from an infinite platformer I'm working on for fun. It belongs to the class GameObject from which every object i.e platforms, player, ...
1k views

I was recently working on a game using the SFML library, Later on, I experienced performance issues due to collision detection. I have been told to use a QuadTree ...
6k views

### Python Turtle based Pong game

I'm new to Python but I've coded in other languages mainly for hardware. I made Pong in Python using turtle but it's a little glitchy. I was wondering if any of you guys could check it out and give ...
407 views

### Octree Implementation

The fn_AABB struct represents an axis aligned bounding box, by a center(position) and half lengths(hwidth). They also contain a set of planes for use in collision but that is not important to the ...
445 views

### Simple class game hierarchy with collision detection

I'm trying to make the transition from the 'understand how standalone features work' phase to writing.. more 'complex' code that could actually see use in real life, so I've been trying find some neat,...
3k views

### Find the intersect area of two overlapping rectangles

This is my solution to find the coordinates of 2 overlapped rectangles implemented in JavaScript. Each rectangle is represented by 2 points, each with 2 (x,y) coordinates. Can this code be improved?...
1k views

### Check if specific key exists in 2-dimensional array

I am writing a "collision detection" in PHP and want to check if a specific "area" is still free in the two-dimensional target array. I use the following code to do that, but I think there might be a ...
345 views

This checks the intersection between a Ray and a Plane and between a Ray and a ...
199 views

### Collision detection accuracy

How do you guys think I can improve the code for collision detection on my website asteroidfield.eu5.org? The current code is ...
153 views

grid.h ...
1k views

### A Quadtree implementation with Colliders

I have created a QuadTree in Java and would like a general code review or suggestions. ...