{"author_link":"\/users\/oneiromancer","author_name":"oneiromancer","author_uid":"oneiromancer","comments":[],"epoch":1602871384,"event":"LD47","format":"md","ldjam_node_id":231393,"likes":5,"metadata":{"p_key":"151622","p_author":"oneiromancer","p_authorkey":"1211993","p_urlkey":"368127","p_title":"A technical rundown of gravity in SkyCrawler","p_cat":"LDJam ","p_event":"LD47","p_time":"1602871384","p_likes":"5","p_comments":"0","p_status":"WAYBACK","us_key":"1211993","us_name":"oneiromancer","us_username":"oneiromancer","event_start":"1601596800","event_key":"76","event_name":"Ludum Dare 47"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD47","removed_author":false},"_superparent":212256,"_trust":2,"author":211993,"body":"*Since gravity is a main feature and a core mechanics of my game, I wanted to write a post about it for quite some time.*\n\nThe idea behind my gravity implimentation is surprisingly easy: find a collision point with a platform, get a normal in this point, use the tangent  and the normal in this point as x and y axis. So, basically, multiply horizontal input by tangent vector, multiply vertical input (or gravity) by normal vector.\n\n![gravity_arrows.gif](\/\/\/raw\/91c\/33\/z\/3a342.gif)\n\nIt isn't really *that* simple, but having circle collider for character and capsule colliders for platforms helps a lot.\n\nFor jumping I would just fix normal vector until I collided with a platform. I also smooth \"horizontal\" movement in air, and to get horizontal velocity in local space I project character velocity on the tangent vector using dot product.\n\n![gravity_arrows2.gif](\/\/\/raw\/91c\/33\/z\/3a343.gif)\n\nBut that's a jam, so of course there are a lot of hacks. I actually have two implimentations of gravity: first uses default Unity physics simulation, and it is used for player character only. But because in the last day of the jam I added an enemy, that needed it's own gravity separate from player, I have a second one, which is a hardcoded gravity specifically for this enemy.\n\n**To see all this stuff in action, try out my game, SkyCrawler: https:\/\/ldjam.com\/events\/ludum-dare\/47\/skycrawler**\n\n![art_promo2.gif](\/\/\/raw\/91c\/33\/z\/3a347.gif)","comments":3,"comments-timestamp":"2020-10-16T18:28:08Z","created":"2020-10-16T17:33:21Z","files":[],"files-timestamp":0,"id":231393,"love":5,"love-timestamp":"2020-11-17T21:50:55Z","meta":[],"modified":"2020-11-17T21:50:55Z","name":"A technical rundown of gravity in SkyCrawler","node-timestamp":"2020-10-16T18:04:33Z","parent":222263,"parents":[1,5,9,212256,222263],"path":"\/events\/ludum-dare\/47\/skycrawler\/a-technical-rundown-of-gravity-in-skycrawler","published":"2020-10-16T18:03:04Z","scope":"public","slug":"a-technical-rundown-of-gravity-in-skycrawler","subsubtype":"","subtype":"","type":"post","version":706263},"node_metadata":{"n_key":"231393","n_urlkey":"368127","n_parent":"222263","n_path":"\/events\/ludum-dare\/47\/skycrawler\/a-technical-rundown-of-gravity-in-skycrawler","n_slug":"a-technical-rundown-of-gravity-i","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"211993","n_created":"1602869601","n_modified":"1605649855","n_version":"706263","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/47\/skycrawler\/a-technical-rundown-of-gravity-in-skycrawler","text":"*Since gravity is a main feature and a core mechanics of my game, I wanted to write a post about it for quite some time.*\n\nThe idea behind my gravity implimentation is surprisingly easy: find a collision point with a platform, get a normal in this point, use the tangent  and the normal in this point as x and y axis. So, basically, multiply horizontal input by tangent vector, multiply vertical input (or gravity) by normal vector.\n\n![gravity_arrows.gif](\/\/\/raw\/91c\/33\/z\/3a342.gif)\n\nIt isn't really *that* simple, but having circle collider for character and capsule colliders for platforms helps a lot.\n\nFor jumping I would just fix normal vector until I collided with a platform. I also smooth \"horizontal\" movement in air, and to get horizontal velocity in local space I project character velocity on the tangent vector using dot product.\n\n![gravity_arrows2.gif](\/\/\/raw\/91c\/33\/z\/3a343.gif)\n\nBut that's a jam, so of course there are a lot of hacks. I actually have two implimentations of gravity: first uses default Unity physics simulation, and it is used for player character only. But because in the last day of the jam I added an enemy, that needed it's own gravity separate from player, I have a second one, which is a hardcoded gravity specifically for this enemy.\n\n**To see all this stuff in action, try out my game, SkyCrawler: https:\/\/ldjam.com\/events\/ludum-dare\/47\/skycrawler**\n\n![art_promo2.gif](\/\/\/raw\/91c\/33\/z\/3a347.gif)","title":"A technical rundown of gravity in SkyCrawler","wayback_source":[]}