Post news Report RSS Javascript Collisions and Optimization

This week I spent a lot of time adding features and optimizing the game framework I created for Kaepe. The main new feature I have added is rotated hitboxes using the separating axis theorem.

Posted by on

This week I spent a lot of time adding features and optimizing the game framework I created for Kaepe. The main new feature I have added is rotated hitboxes using the separating axis theorem. I have uploaded the code at jsdo.it if you would like to take a look. The only important function is the is_colliding(obj1, obj2) function. which returns either true (if a collision has occurred) or false if they are not touching. I have found that on my computer, with my browser, each collision takes less than a millisecond. I have conservatively estimated it takes about .01 of a millisecond on average. That means I could have roughly 3000 checks per second if my game was running at 30 ticks a second.

1s/30ticks = 33.33 ms a tick
33.3/.01=3330 collision checks a second

jsdo.it source code

If you would like to test it I would love to hear the averages your computer pulls! I am still actively working to speed the entire engine up.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: