The Stack Overflow podcast is back! Listen to an interview with our new CEO.

# 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
693 views

### Conditionally eliminating one of two colliding bodies

I like to explicit return function even for void functions to reduce the use of if-elses, like this code snippet: ...
14k views

### Detecting collision of two divs

I have two divs as seen in this JSFiddle. To recreate the problem, keep clicking on the Gray container till both divisions touch each other. The purpose is to ...
184 views

### Platformer Game: Arrow Key Player Movement and Collision Detection

I am in the middle of working on this game and I still need to add some things (e.g. score, coin counters, etc.) but I really feel like there is way too much unneeded code. Could you help me simplify ...
656 views

### Intersection-detection algorithm

This is an intersection-detection algorithm I developed as an alternative method to the one developed for my coursework. I won't post some of the other functions as they are used in the coursework too,...
147 views

### Flood Fill using unordered_map which has user-defined type as key

I have an implementation of the flood fill algorithm. Assume that an image is provided as a vector of ...
348 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 ...
300 views

### Maximize the number of PyGame sprites, with collision detection

I was trying to see what is the highest number of moving and colliding boxes (sprites) I could get in pygame? So that I could start working on game I want, I searched google and I found different ...
48 views

### Making a grid for collision detection in a game that wraps

I'm making a 2D game which wraps (when you move off the right edge, you appear on the left, etc). The game area is square, all objects are circles (with AABB smaller than the game area, and in most ...
2k 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?...
174 views

I have an implementation of a BrickBreaker-like game where instead of pieces being just removed from the ceiling, each impact results in a new ball being released, gradually building up to a pretty ...
800 views

### Circle - Line segment collision

I wrote an implementation of circle - line segment collision detection algorithm. Here is quick demonstration how it works: And here is my implementation in Javascript using HTML canvas: index.html ...
754 views

### Simple geometry problems involving rectangles and circles in Python 3

I'm working with some simple geometry problems featuring rectangles and circles. My code is as follows: ...
210 views

### Checking a circle against some bounds in a collision detector

First, some code. I have a class, Circle: ...
398 views

### Canvas spatial grid collision

You can see a working example here. Be sure to click on the canvas or the key inputs will not be detected! Are there any ways I could improve upon this? Anything that should have been done ...
6k views

### Java Slick 2D Collision Detection Methodology

I have a collision detection for terrain setup (non-terrain is handled with a quadtree I implemented apart from this) and I was wondering how others have done it compared to mine and what I could ...
137 views

### Weeding out triangles for triangle-triangle collision detection using a spatial hash

I am implementing a multi-phase collision detection system whose final collision check is checking the triangles of one shape against those of another. As the number of triangle-triangle comparisons ...
61 views

### Find cells crossed by a line

This method find cells that are crossed by line A-B and adds them to one vector. I have got some duplicates here and some lines of code are very similiar but they differ in one variable. Should this ...
3k views

### Pong Game in WinForms

I've wanted to make a Pong game for awhile, so I eventually got around to it now, it didn't take that long except for the reflections which I unfortunately didn't end up being satisfied with. I wanted ...
233 views

### C++ Breakout game using SDL

I did a big mistake to create procedural C++ breakout game on start and now im having trouble converting it into OOP. As far as I can see I need classes: Loptica (eng. Ball), Splav (eng. Paddle), ...
354 views

### Checking whether a bullet has hit a Space Invader

I just (almost) finished a Space-Invaders game in Javascript. I have a few bugs to clear out of the way but meanwhile I wanted to ask how I can improve the method I use to test if one of my 'Bullets' ...
44 views

### Check for collision with side of screen

I thought of a program where you move a square with the arrow keys. I created it and asked a question about it on Stack Overflow. I copied the last code block of the accepted answer and tried to ...
1k views

### Thread, handler and activity structure for a bouncing ball animation

This is a custom MyActivity class with two custom views (bar and a ball): ...
997 views

### High performance, branchless Intersection testing: sphere-aabb & aabb-aabb

From my tests: AABB-Sphere: 2954.8 tests per ms. AABB-AABB: 1087.0 tests per ms. The sphere test is almost 3 times faster, but the two intersection tests seem to perform about the same number ...
1k views

### Java Pong Game Collision between bat and ball

I have a very simple Pong game that I've built in Java. The code is quite long so I've decided to focus this question on the collision that occurs with the ball and the bat and also the effects in the ...
303 views

### Collision detection inconsistencies [closed]

I've been wondering about simple collision in C++ for a while now, and I've tried to make up my own code. The code posted below works when walls are placed in a perfect rectangle around the player. ...
59 views

### Calculating all combinations to make sure a Random algorithm has done them all

I have done this, but it's pretty ugly and it feels like I may be missing something to shorten it: ...
2k views

### Optimizing snap SVG animation with collision detection

I have a snap SVG animation which animates a bunch of circles, and draws a line between them if they are within a certain proximity of each other. However, I realize that there is a lot of optimizing ...
3k views

### Collision detection algorithm

This is my second algorithm and I will try to make it as simple for you to understand how it works. It is pretty expensive and I'd like to make it more efficient. . It works by splitting a square ...
137 views

### Simplify JavaScript collision detection with offset [closed]

I am working on a background project that is a little interactive. Now I am using some collision detection to draw some lines and stuff. The code I have works great but it is very bulky and hard to ...
215 views

### Log collisions in generating unique random strings

I've created a small class to generate unique random strings. It works fine. I also want to log the collisions of the generated strings. I check if the generated string is in the array for uniquness: ...
244 views

### Breakout-like game in JS

I've made a small breakout game, so far with one level. My plan is to expand it so that it has a level editor, but for now I wanted to make sure that everything is currently looking well-designed. I ...
78 views

### Collision manager

I have a chunk of code that's working properly but it's way too complicated to read: ...
261 views

### Javascript collision check

I have code to find images in my selections. But when nothing in selection (loop FOR) and selection is kinda big, it's kinda laggy. How can I improve my code? ...
80 views

### FPS efficiency for 'attack counter'

I have a code snippet which I wish to improve to increase my program's FPS, but as a beginner in JavaScript, I do not know how. I know the problem, which is the fact my counter mechanism used to delay ...
172 views

### Unit tests for collisions

I'm finding it a bit tedious to write unit tests for my collision class because there are so many variations of collisions that need testing. I see repetition in the set-up and assertion stages of ...
113 views

### Checking whether two strokes overlap [closed]

I have these two functions and I was just wondering if there is any way to shorten the line of code with the many && statements. Shortening of the rest of the code would be cool too, but it's ...
28 views

### More JS AI causes slower AI movement in HTML Canvas

I have a simple little game with one character as the player and four enemy characters. I created a very basic AI, that moves towards the player when the player is nearby. That all worked fine, but ...
175 views

### Recreating pong

Github is a link to all my code and the working JAR file. I have been learning LibGDX and attempted to make a working Pong game, I am new to this and would like some pointers on where I could improve ...
208 views

### Second attempt at canvas spatial grid collision

After posting my first question and my first attempt which you can see here: Canvas spatial grid collision I have re-written it to try and implement what the person gave as an answer. I didn't do ...
177 views

### Does this intersection algorithm work like it's supposed to? [closed]

and can I make it more efficient? It's to test the collision between a ray and a sphere. ...
48 views

I'm making a simple 2D game engine, and to make collision detection more effective I tried making a QuadTree class. I don't know if this will work, but that's not that important. You don't have to ...
2k views

### C++ Erasing an object from vector of pointers

I am making this simple game in SFML and I have this vector of pointers std::vector<Brick*> bricks; which stores objects of class ...
24 views

### Collision Detection Code doesn't detect all the collision [on hold]

I am doing capsule-capsule collision detection. It's not perfect; it lets through some collisions. I'm thinking it may have to do with floating point error, but I don't know how to correct for that. I ...