Skip to main content

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password
Register
  • Home
  • Browse
    • 2D Art
    • 3D Art
    • Concept Art
    • Textures
    • Music
    • Sound Effects
    • Documents
    • Featured Tutorials
  • Submit Art
  • Collect
    • My Collections
    • Art Collections
  • Forums
  • FAQ
  • Leaderboards
    • All Time
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
    • Weekly
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
  • ❤ Donate
Programming

collision in game

ǝıuusןısn
Friday, July 19, 2019 - 23:32

how do collision is calculated in game?

so that characters dont fall through the floor, stop at walls, and not clip in? maybe also walk on tilted floors and be angled?

do they use placeholders to test the physics? of what kind?

how are these dones, by example, C++ or pythons? C#? lisp?
logically, where are the parameters written between object to object so things connect?

  • Log in or register to post comments
withthelove
joined 11 years 3 months ago
Saturday, July 20, 2019 - 08:39
withthelove's picture

 

There are many, many different ways to handle collisions in games.

The simplest approach is just to assign each object a rectangle.  This is often called a 'collision box'.  Then you just check all the rectangles against one another.  If any overlap, you have a collision.

If you're looking for a library to save yourself the trouble of writing collision detection routines yourself, try this link:

https://github.com/jslee02/awesome-collision-detection

https://withthelove.itch.io/

  • Log in or register to post comments
ǝıuusןısn
joined 5 years 10 months ago
Saturday, July 20, 2019 - 17:31

Oh wow, amazing. 
I definitely want to write it myself,with some adjustments.

thanks for the link, i am browsing it.

so technically, that collission is definitely an overlap in computers? not when the edge touches one another?

  • Log in or register to post comments
withthelove
joined 11 years 3 months ago
Sunday, July 21, 2019 - 04:41
withthelove's picture

> so technically, that collission is definitely an overlap in computers? not when the edge touches one another?

That depends on how you write the tests.  If you are using collision boxes, you can write the collision tests to either include the case where the edges touch or not.  It's just a matter of how you write the test and wether you use a > or a >= in your comparisons.

 

 

https://withthelove.itch.io/

  • Log in or register to post comments
ǝıuusןısn
joined 5 years 10 months ago
Thursday, July 25, 2019 - 22:50

So, i guess you can't really catch a bug and glitch when it happens?

pinpointing the exact mistake?

  • Log in or register to post comments
nateonus
joined 5 years 9 months ago
Friday, July 26, 2019 - 10:09
nateonus's picture

As someone who has *attempted* to create a collision & physics system, I highly recommend using a pre-built library. There is SO much that you have to do, and it's very difficult to say the least.

Simple collision detection isn't too complex. Using a bounding-box collision system, where you have a square for each collision object is one of the most simple and effective ways of doing collision.

What gets complex is when you have to work out what to do after that.

If two objects collide, do they bounce off of each other? How much friction is applied? How much do the objects weigh, and how does gravity and other external forces affect this? If a character collides with a wall, what actually stops him from clipping through the wall? If the characters velocity is too high or not stopped correctly, your character may get stuck in the wall or floor.

That's not even scratching the surface. There's so much more to think about...

Good luck with it though, let me know how it goes!

(Look at Box2D if you give up ;) )

  • Log in or register to post comments
ǝıuusןısn
joined 5 years 10 months ago
Friday, July 26, 2019 - 17:11

yeah but which library is good?

 

you just try every single library for best results?

  • Log in or register to post comments
nateonus
joined 5 years 9 months ago
Saturday, July 27, 2019 - 01:21
nateonus's picture

Base your collision and physics off of a project that's already been done, and find out what physics engine it uses.

Box2D is probably the best library for 2D physics in my opinion. Just look at a tutorial to make it work, cause it is quite complex to implement.

  • Log in or register to post comments
Pro Sensory
joined 8 years 3 months ago
Sunday, April 3, 2022 - 21:44
Pro Sensory's picture

This is a link to a course that teaches 2D Physics. It is of excellent quality.

https://pikuma.com/

Alex McCulloch

  • Log in or register to post comments
Simx72
joined 4 years 1 month ago
Thursday, September 5, 2024 - 19:44
Simx72's picture

When I was learning Javascript, I made some kind of approach to collision:

 

https://simx72.github.io/Pong/

it isn't actual collision but overlap. The problem is that after some time playing (like 5 min) the ball goes so fast that it would just jump over the paddle and not bounce. The game is in Spanish but its simple pong, controls are w,s for left and up/down_arrow for right. When you get to that point, you'll notice how the ball would just not bounce but pass the paddle as if it was invisible. I never knew how to fix it nor interested about it but since I always use libraries xd, don't know how they work but they do. For physics, which includes collision, gravity, etc, I like phaser.js

 

Simx72 :)

  • Log in or register to post comments