{"id":20949631,"url":"https://github.com/tckerr/collision","last_synced_at":"2026-04-21T18:32:30.932Z","repository":{"id":147009244,"uuid":"49779765","full_name":"tckerr/Collision","owner":"tckerr","description":"Collision is a Javascript library that provides basic 2D OBB collision detection and resolution.","archived":false,"fork":false,"pushed_at":"2016-01-16T15:54:01.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-19T22:36:08.304Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tckerr.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-16T15:51:35.000Z","updated_at":"2020-05-10T20:52:13.000Z","dependencies_parsed_at":"2023-04-18T07:31:00.135Z","dependency_job_id":null,"html_url":"https://github.com/tckerr/Collision","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tckerr%2FCollision","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tckerr%2FCollision/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tckerr%2FCollision/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tckerr%2FCollision/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tckerr","download_url":"https://codeload.github.com/tckerr/Collision/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243345615,"owners_count":20275872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T00:41:14.275Z","updated_at":"2025-12-24T18:17:13.964Z","avatar_url":"https://github.com/tckerr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Description\n---\nCollision is a Javascript library that provides basic 2D rectangular [OBB](https://en.wikipedia.org/wiki/Bounding_volume) collision detection and resolution. To see an example in action, check out this [asteroid generator](http://www.tckerr.com/cdr/) (turn off \"immune\" in the options.)\n\n\nInstructions\n---\n\nDownload and include the library:\n\n```\n\u003cscript src=\"lib/collision.min.js\"\u003e\u003c/script\u003e\n```\n\nYou will then be able to access the library through the ```Collision``` object. First, set up your objects with axis-aligned bounding boxes, like so:\n\n```\nvar A = {\n    UL: {x: 10, y: 10},\n    UR: {x: 59, y: 10},\n    LR: {x: 59, y: 59},\n    LL: {x: 10, y: 59}\n}\nvar B = {\n    UL: {x: 110, y: 80 },\n    UR: {x: 159, y: 80 },\n    LR: {x: 159, y: 159},\n    LL: {x: 110, y: 159}\n}\n```\n\nTo test for collision, simply run ```Collision.test(A,B);```, where A is the object who is in motion. The resulting object will have the following properties:\n\n- ```did_collide```: A boolean representing collision or not.\n- ```entity```: The object that A is in collision with (in this case, B)\n- ```projection```: The resolution vector for object A. This is an object like ```{x: 5, y: -10}``` such that adding those values to each of A's coordinates will resolve collision. Note: if there is no collision, this property will always be ```{x: 0, y: 0}```\n\nExamples\n---\n\n*Here are two objects not in collision:*\n\n![no collision](http://i.imgur.com/LZAdSdv.jpg)\n\nHere is their object representations:\n\n```\nvar A = {\n    UL: {x: 10, y: 10},\n    UR: {x: 59, y: 10},\n    LR: {x: 59, y: 59},\n    LL: {x: 10, y: 59}\n}\nvar B = {\n    UL: {x: 110, y: 80 },\n    UR: {x: 159, y: 80 },\n    LR: {x: 159, y: 159},\n    LL: {x: 110, y: 159}\n}\n```\n\nRunning test return false:\n\n```\nCollision.test(A,B); //did_collide will return false\n```\n\n*Here we have two objects in collision:*\n\n![collision](http://i.imgur.com/ZjWejzw.jpg)\n\nHere is their object representations:\n\n```\nvar A = {\n    UL: {x: 30, y: 20},\n    UR: {x: 59, y: 20},\n    LR: {x: 30, y: 89},\n    LL: {x: 59, y: 89}\n}\nvar B = {\n    UL: {x: 40, y: 70},\n    UR: {x: 99, y: 70 },\n    LR: {x: 99, y: 99},\n    LL: {x: 40, y: 99}\n}\n```\n\nLet's check for collision, then add the result to A:\n\n```\nvar result = Collision.test(A,B); //did_collide will return true, so add the projection\nA = {\n    UL: {x: 30+result.projection.x, y: 20+result.projection.y},\n    UR: {x: 59+result.projection.x, y: 20+result.projection.y},\n    LR: {x: 30+result.projection.x, y: 89+result.projection.y},\n    LL: {x: 59+result.projection.x, y: 89+result.projection.y}\n}\nvar result = Collision.test(A,B); //did_collide will return false\n```\n\nHere is the result of adding the projection -- no collision:\n\n![resolved](http://i.imgur.com/SZZAaBq.jpg)\n\nThis is a simple example using axis-aligned boxes. See the example in the description for an implementation that uses oriented bounding boxes. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftckerr%2Fcollision","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftckerr%2Fcollision","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftckerr%2Fcollision/lists"}