Skip to main content

Questions tagged [collision]

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

2 votes
1 answer
93 views

Efficiently generate a random position inside an outer rectangle but outside an inner rectangle

It should be a uniform distribution (ie: every point is equally as likely). I also don't want to use the simple solution of: "in a loop check to see if the current generated point is within the ...
Ryan Peschel's user avatar
0 votes
1 answer
139 views

Object Collision in Breakout game using SDL library [closed]

Im trying to make a retro game of Breakout using an SDL library. Im still trying to learn developing and OOP. I got to the part where i want to check for collision between paddle and the ball, and ...
bboyMinato's user avatar
6 votes
3 answers
281 views

Intersecting rectangles on a torus

Description Imagine a space like the arcade game Asteroids where everything wraps around right to left and bottom to top - effectively coordinates on a flat torus. The diagram shows an example of two ...
FreddyFlares's user avatar
5 votes
1 answer
421 views

Simple Ellipse Collision Mini Game

I am doing an exercise to help me understand C#and OOP. The exercise is supposed to teach me about ...
Darke's user avatar
  • 163
3 votes
1 answer
129 views

A Spatial Hash View: Store references to spatial data so it can be used for performant broad phase collision detection

I have created a non-owning view of some spatial data that organises the data into cells. The data is split into a grid of cell size 100, and the key to the ...
Blue7's user avatar
  • 373
2 votes
2 answers
352 views

Movement and collision function

I just want this code optimized to the max and I don't mind knowing if the optimization is pretty much at the max already or if I am doing movement and collision wrong. My game is a 2d Minecraft style ...
coder's user avatar
  • 179
2 votes
1 answer
363 views

Simulation of sand particle collision

I am making a module that allows you to create sand and simulate it. I have successfully done this, but it runs very slowly. I need this to be able to simulate at least 1000 particles, at a fps higher ...
susthebus's user avatar
4 votes
2 answers
289 views

Revised Top-Down Dungeon RPG

Introduction: So far, the game works well, and my only major concerns, are a bullet system (including a function where you click the mouse to shoot the bullets), and a collision system between the ...
Zelda's user avatar
  • 123
5 votes
1 answer
197 views

Convex polygon-polygon swept collision test

Currently working on a pre-solve collision library. My goal is to have it be potentially usable in potential video game projects of mine, so time constraint is small as this should be used in a game ...
sfbea's user avatar
  • 61
9 votes
1 answer
1k views

Generate unique random strings considering collisions

I'm coding a random strings generator. It's working, but I'm not sure if this is efficient. ...
user2652379's user avatar
5 votes
1 answer
2k views

Python - 2D Elastic Collision Simulation

I am currently a Python beginner, who just finished a script simulating collisions between circles (balls) in 2 dimensions. I would appreciate comments on overall structure, variable names and really ...
JSogaard's user avatar
  • 151
4 votes
1 answer
215 views

A library of 2D Shapes with functions for their intersections

The goal was as much code reuse as I could get. Shooting for a pure-function-y style. Would love any feedback on general architecture, adherence to standard practice and usability - as well as ideas ...
Ty Miles's user avatar
  • 185
11 votes
1 answer
539 views

Battle City (Tank) replica

I'm learning JS and Canvas. A friend of mine gave me the task to create a Battle City replica. I've already managed to make the map and the player to move. Nothing fancy just some squares with a color,...
Frakcool's user avatar
  • 181
2 votes
1 answer
68 views

Creating restrictions for a sprite's possible position on the screen

The great feedback I got on my first post on Code Review made me wary of code repetition. This code does what it is supposed to, which is to create restrictions for a sprite's possible position on the ...
ola_bandola's user avatar
2 votes
0 answers
215 views

Typescript QuadTree

everybody. It took a tree of squares for my web game. I wrote a preview using Typescript. I would like to hear from you tips on how to improve the code (I just started writing in Typescript). First ...
12345654321's user avatar
16 votes
3 answers
7k views

2D Collision Detection in C++

I'm attempting to rewrite the classic snake game in c++. What I am inquiring about is my implementation for a 2D collision detection function. I am utilizing ...
Linny's user avatar
  • 10.3k
4 votes
1 answer
190 views

Creating a maze game where the game resets if you hit traps/walls and finishes when you hit a different color

Here’s my code, the traps are the slightly visible squares. The user controls a red square (with arrow keys) and cannot touch the walls or traps or else the game resets. Additionally, if the user ...
Nicocav6's user avatar
3 votes
1 answer
202 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 ...
Shuri2060's user avatar
  • 227
4 votes
1 answer
1k views

Bounding volume hierarchy C++

Here is a C++ implementation of a bounding volume hierarchy, aimed for fast collision detection (view frustum, rays, other bounding volumes). It is based on the ideas from the book "Real-Time ...
user avatar
1 vote
2 answers
237 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 ...
JanWillem Huising's user avatar
0 votes
1 answer
76 views

Self Updtating QuadTree

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 ...
Kristóf Bácskai's user avatar
2 votes
1 answer
602 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), ...
Marko Petričević's user avatar
3 votes
1 answer
272 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 ...
skr's user avatar
  • 539
5 votes
2 answers
10k 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 ...
Remington Nachshin's user avatar
5 votes
1 answer
779 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 ...
DarkWiiPlayer's user avatar
3 votes
2 answers
307 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 ...
Josh Berger's user avatar
5 votes
1 answer
307 views

Line and bitmap collision detection

I am trying to implement an efficient collision detection between a line joining two points and a bitmap mask. Example: Currently I am using Bresenham's line drawing algorithm to draw each pixel of ...
Alessi 42's user avatar
  • 153
6 votes
2 answers
962 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 ...
Plqsmic's user avatar
  • 197
5 votes
1 answer
50 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 ...
MegaIng's user avatar
  • 413
6 votes
3 answers
249 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]. ...
geofflittle's user avatar
5 votes
2 answers
499 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 ...
Carlos Hdez Barbera's user avatar
4 votes
1 answer
3k 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 ...
Tomek's user avatar
  • 315
4 votes
1 answer
901 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,...
string_loginUsername's user avatar
7 votes
2 answers
8k 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?...
Achref Boukhili's user avatar
4 votes
1 answer
598 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 ...
J. H's user avatar
  • 199
6 votes
1 answer
404 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 ...
Ben Beri's user avatar
4 votes
1 answer
378 views

Spatial Hash for optimizing AABB collisions

grid.h ...
J. H's user avatar
  • 199
5 votes
0 answers
238 views

Spacial hashing Library

Old code ...
Tobi's user avatar
  • 241
1 vote
1 answer
86 views

Collision manager

I have a chunk of code that's working properly but it's way too complicated to read: ...
Tiago Marinho's user avatar
5 votes
1 answer
347 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 ...
SJJ's user avatar
  • 51
-2 votes
1 answer
6k 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 ...
user avatar
3 votes
2 answers
737 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 ...
مهند عبد الجليل's user avatar
2 votes
2 answers
669 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' ...
Guy W's user avatar
  • 21
1 vote
2 answers
395 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? ...
Vito24's user avatar
  • 11
5 votes
0 answers
275 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, ...
kainev's user avatar
  • 301
13 votes
2 answers
10k 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 ...
Tyler C's user avatar
  • 325
2 votes
2 answers
2k 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 ...
jpx's user avatar
  • 29
3 votes
1 answer
1k 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: ...
SassySamurai's user avatar
7 votes
1 answer
186 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 ...
Bomaz's user avatar
  • 297
1 vote
1 answer
255 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: ...
akinuri's user avatar
  • 199

15 30 50 per page