Jump to content
• Advertisement

# Collision Detection

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

If you intended to correct an error in the post then please contact us.

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

#### Share this post

##### Share on other sites
Advertisement

• Advertisement
• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• Advertisement

• ### Popular Now

• 9
• 11
• 15
• 21
• 26
• Advertisement
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!