Questions tagged [collision-detection]

Collision detection is the determination of whether or not two or more entities make contact with each other during gameplay.

Questions about how to implement collision detection or dealing with specific implementations and scenarios which complicate the process fall under the purview of this tag.

This includes questions about methods to assist in developing a collision detection system, such as how to determine the points of shortest distance between two objects.

2505 questions
84
votes
6 answers

How does a collision engine work?

How exactly does a collision engine work? This is an extremely broad question. What code keeps things bouncing against each other, what code makes the player walk into a wall instead of walk through the wall? How does the code constantly refresh the…
JXPheonix
  • 943
  • 2
  • 7
  • 7
76
votes
12 answers

most efficient AABB vs Ray collision algorithms

Is there a known 'most efficient' algorithm for AABB vs Ray collision detection? I recently stumbled accross Arvo's AABB vs Sphere collision algorithm, and I am wondering if there is a similarly noteworthy algorithm for this. One must have condition…
Dollarslice
  • 3,490
  • 6
  • 35
  • 49
75
votes
13 answers

What is the fastest way to work out 2D bounding box intersection?

Assume that each Box object has the properties x, y, width, height and have their origin at their center, and that neither the objects nor the bounding boxes rotate.
Iain
  • 6,568
  • 3
  • 36
  • 47
61
votes
9 answers

How to avoid circular dependencies between Player and World?

I'm working on a 2D game where you can move up, down, left and right. I have essentially two game logic objects: Player: Has a position relative to the world World: Draws the map and the player So far, World depends on Player (i.e. has a reference…
futlib
  • 1,477
  • 15
  • 21
52
votes
7 answers

2D Platformer AABB collision problems

I have a problem with AABB collision resolution. I resolve AABB intersection by resolving the X axis first, then the Y axis. This is done to prevent this bug: https://i.sstatic.net/NLg4j.png The current method works fine when an object moves into…
Vittorio Romeo
  • 1,200
  • 3
  • 16
  • 33
47
votes
4 answers

A ball hits the corner, where will it deflect?

I need to brush up my trigonometry and hope you can help here with a simple mathematical model. Here is my model so far in the image attached. I am aware that the frame animation has other problems when the ball is moving very fast, but for now I…
Lumis
  • 964
  • 3
  • 10
  • 21
42
votes
1 answer

How to differentiate landing on top of an object from falling down the side?

I am looking for a conceptual solution to my problem. It's a simple platformer-alike game where player can move horizontally during free-fall. Consider those two cases: In the first case, from game experience point of view, the player should land on…
weno
  • 541
  • 4
  • 10
39
votes
6 answers

Hexagon collision detection for fast moving objects?

A object has a position and a speed vector. Usually only the position is used to check if two objects collide, this is problematic for very fast moving objects as it can happen that the object moves so fast that it is in front of the first object in…
API-Beast
  • 6,869
  • 1
  • 30
  • 44
35
votes
3 answers

How many and which axes to use for 3D OBB collision with SAT

I've been implementing the SAT based on: Dynamic Collision Detection using Oriented Bounding Boxes [PDF] On page 7, in the table, it refers the 15 axis to test so we can find a collision, but with just Ax, Ay and Az, I'm already getting collisions.…
GriffinHeart
  • 610
  • 1
  • 5
  • 9
35
votes
6 answers

How do I calculate distance between a point and an axis-aligned rectangle?

I have a 2D rectangle with x, y position, height and width, and a randomly positioned point nearby. Is there a way to check if this point might collide with the rectangle if it is closer than a certain distance? Imagine an invisible radius outside…
john smith
  • 483
  • 2
  • 5
  • 7
30
votes
2 answers

Quad tree vs Grid based collision detection

I'm making a 4 player co-op r-type game, and I'm about to implement the collision detection code. I've read a lot of articles and stuff about how to handle collision detection, but I'm having a hard time figuring out what to go with. It seems the…
dotminic
  • 1,637
  • 2
  • 20
  • 26
29
votes
6 answers

How to decide which GameObject should handle the collision?

In any collision, there are two GameObjects involved right? What I want to know is, How do I decide which object should contain my OnCollision* ? As an example, let's suppose I have a Player object and a Spike object. My first thought is to put a…
Redtama
  • 405
  • 4
  • 9
28
votes
6 answers

What is a good algorithm to detect collision between moving spheres?

If (for the purpose of collision detection) 3D objects are represented in a game by spheres, what is a good algorithm to detect a collision between spheres? If each object has a position as of the last frame and a new (desired) position, what is a…
kevin42
  • 4,516
  • 6
  • 30
  • 33
27
votes
3 answers

OBB vs OBB Collision Detection

Say you have two Bounding Box Objects each of them storing the current vertices of the box in a vector with all the vertices of the object rotated and translated relative to a common axis. Here is an image to illustrate my problem: How can I work…
jshbrntt
  • 575
  • 1
  • 7
  • 18
25
votes
5 answers

Collision Resolution

I know quite well how to check for collisions, but I don't know how to handle the collision in a good way. Simplified, if two objects collide I use some calculations to change the velocity direction. If I don't move the two objects they will still…
CiscoIPPhone
  • 5,288
  • 3
  • 35
  • 39
1
2 3
…
99 100