Sign in to follow this  
martensms

Collision Detection

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.


[b]So what am I doing there?[/b]

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

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


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this