# Collision Detection

This topic is 2629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey everyone,

I'm pretty new when it comes to game physics. I was wondering that anyone likes to prefer Box2D, which is pretty common for web games.
I was a C-guy that moved to JavaScript and I'm currently experimenting a lot when it comes to games in web browsers.

There's my evolved concept based on speed deltas. Don't know if it's effective, it's mostly for myself to understand simple (emulated) game physics.

So I tried to build a little platformer which can be found either on github or here:
http://sandbox.martens.ms/game

(currently it uses canvas for rendering, but can be switched to DOM, too)

The thing with collision detection happens inside the physics.js.

So what am I doing there?

The relevant code of the physics.js is here:
https://github.com/martensms/sandbox/blob/master/game/js/physics.js#L216

I'm determining of an object collides with another object (oObject). It's a bit uneffective that everything is within the data hashmap, will move that upper for faster access times.

The relevant thing is that there are squares,
the first square (A,B,C,D) is the one of the object with added speed deltas. The speed deltas are the absolute value of both object's velocities.
the second square (E,F,G,H) is the one of the object itself. So it's the same values like the "polygons" positions of the object later.
the third square (I,J,K,L) is the one of the _other_ object itself. So it's mostly for determining where the other object is and where it's moving to (in which direction etc.)

It seems to work pretty fine, but I've got some glitch cases with >= instead of >, that's why the player's object (the blue square) in the demo is now colliding with the right horizontal object when he gets dropped into the world.

What do you think about that concept?
Please let me know if you have suggestions, advices and comments on any kind - because I'm new to the game sector and want to learn pretty anything =)

Greets,
Chris

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633766
• Total Posts
3013732
×