{"id":270,"date":"2018-06-09T22:21:33","date_gmt":"2018-06-10T03:21:33","guid":{"rendered":"http:\/\/www.chroniclesoftright.com\/blog\/?p=270"},"modified":"2018-06-09T22:21:33","modified_gmt":"2018-06-10T03:21:33","slug":"collision-system-refactoring","status":"publish","type":"post","link":"https:\/\/www.chroniclesoftright.com\/blog\/2018\/06\/09\/collision-system-refactoring\/","title":{"rendered":"Collision system refactoring"},"content":{"rendered":"<p style=\"text-align: justify;\">I have rearranged the code from Fauerby&#8217;s paper into a single Javascript function (class) in a separate file.\u00a0 I called it CollisionSystem and a single instance of that function keeps up with everything related to collisions.\u00a0 Fauerby used a &#8220;CollisionPackage&#8221; (or &#8220;CollisionPacket&#8221;, depending on where you look in the code) to pass variables to the collision functions.\u00a0 I moved that into a single class with the appropriate members and methods.\u00a0 So now my code looks like this:<\/p>\n<p><code>var _cs = new CollisionSystem();<\/code><\/p>\n<p><code>_cs.collisionTargets.push(collidableObject);<\/code><\/p>\n<p><code>var newPosition = _cs.run(position, velocity);<\/code><\/p>\n<p><code>position = newPosition;<\/code><\/p>\n<p>Once the <code>CollisionSystem<\/code> is created and at least one <code>collisionTarget<\/code> is added to it, I just call <code>run<\/code> with the collider&#8217;s current position and velocity.\u00a0 <code>run<\/code> returns the new position and I can then update the scene with that position.\u00a0 Easy peasy chicken squeezy.<\/p>\n<p>A current limitation of the system is that I&#8217;m not implementing gravity right now.\u00a0 That will need to be done eventually, but I thought I could add that later after the core system is running.\u00a0 I&#8217;m also not taking a <code>collidableObject<\/code>&#8216;s rotation into account at the moment.\u00a0 This will obviously need to be implemented but it shouldn&#8217;t be difficult at all.\u00a0 I&#8217;ll need to look through the code to confirm this but I believe that the collider has a hard-coded radius of 1.\u00a0 Since the base unit in Lyridia is 1 meter, a collider sphere with a diameter of 2 meters is really just too big for a humanoid player character, so that will need to be adjusted.<\/p>\n<p>My next step is to take my CollisionSystem class and bring it into the rest of Lyridia&#8217;s code base.\u00a0 The only real challenge with that is that the player doesn&#8217;t move based on velocity directly right now, but that should be easy to change.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have rearranged the code from Fauerby&#8217;s paper into a single Javascript function (class) in a separate file.\u00a0 I called it CollisionSystem and a single instance of that function keeps up with everything related to collisions.\u00a0 Fauerby used a &#8220;CollisionPackage&#8221; (or &#8220;CollisionPacket&#8221;, depending on where you look in the code) to pass variables to the&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-270","post","type-post","status-publish","format-standard","hentry","category-planning-and-development"],"_links":{"self":[{"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/posts\/270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/comments?post=270"}],"version-history":[{"count":2,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":272,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions\/272"}],"wp:attachment":[{"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/media?parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/categories?post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chroniclesoftright.com\/blog\/wp-json\/wp\/v2\/tags?post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}