{"author_link":"\/users\/machwerx","author_name":"MachWerx","author_uid":"machwerx","comments":[],"epoch":1619999234,"event":"LD48","format":"md","ldjam_node_id":255966,"likes":6,"metadata":{"p_key":"157532","p_author":"MachWerx","p_authorkey":"1141432","p_urlkey":"377779","p_title":"Snake on a Sphere: Procedural Meshes","p_cat":"LDJam ","p_event":"LD48","p_time":"1619999234","p_likes":"6","p_comments":"0","p_status":"WAYBACK","us_key":"1141432","us_name":"MachWerx","us_username":"machwerx","event_start":"1619222400","event_key":"109","event_name":"Ludum Dare 48"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD48","removed_author":false},"_superparent":233335,"_trust":4,"author":141432,"body":"The main character of my game \"[Snake on a Sphere](https:\/\/ldjam.com\/events\/ludum-dare\/48\/snake-on-a-sphere)\" is a snake ... on a sphere but what people might not be aware of is that this character is entirely generated in code.\n\n![3b968.gif](\/\/\/raw\/878\/22\/z\/420df.gif)\n\nPart of the reason is that I'm not that proficient with modeling, articulating, and animating. But even if I was, there's a lot of power in creating the mesh in code. So roughly, there are two things you have to do:\n\n  * Define the vertices of the mesh.\n  * Define the triangles of the mesh.\n\nIn my case, I wanted to have a snake, so it's roughly a squiggly cylinder. The way I created that was to define a spine that trails behind the head and then for each point in that spine, I define a coordinate system:\n\n  * \"Forward\" is in the direction between each point and the point in front of it.\n  * \"Up\" is away from the center of the sphere.\n  * \"Right\" is the vector cross product of the previous two.\n\nNow we can define a circle using \"Up\" and \"Right\" and then connect up neighboring circles with the appropriate triangles between circles and voila, we have a snake! Well there's a little more to it with shaping of the head and such, but that's the basic idea. You can see more details in [the code for my snake](https:\/\/github.com\/MachWerx\/SnakeOnASphere\/blob\/main\/Assets\/Scripts\/Snake.cs). Enjoy!","comments":0,"created":"2021-05-02T23:26:31Z","files":[],"files-timestamp":0,"id":255966,"love":6,"love-timestamp":"2021-05-05T02:58:44Z","meta":[],"modified":"2021-05-05T02:58:44Z","name":"Snake on a Sphere: Procedural Meshes","node-timestamp":"2021-05-02T23:47:14Z","parent":241393,"parents":[1,5,9,233335,241393],"path":"\/events\/ludum-dare\/48\/snake-on-a-sphere\/snake-on-a-sphere-procedural-meshes","published":"2021-05-02T23:47:14Z","scope":"public","slug":"snake-on-a-sphere-procedural-meshes","subsubtype":"","subtype":"","type":"post","version":787011},"node_metadata":{"n_key":"255966","n_urlkey":"377779","n_parent":"241393","n_path":"\/events\/ludum-dare\/48\/snake-on-a-sphere\/snake-on-a-sphere-procedural-meshes","n_slug":"snake-on-a-sphere-procedural-mes","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"141432","n_created":"1619997991","n_modified":"1620183524","n_version":"787011","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/48\/snake-on-a-sphere\/snake-on-a-sphere-procedural-meshes","text":"The main character of my game \"[Snake on a Sphere](https:\/\/ldjam.com\/events\/ludum-dare\/48\/snake-on-a-sphere)\" is a snake ... on a sphere but what people might not be aware of is that this character is entirely generated in code.\n\n![3b968.gif](\/\/\/raw\/878\/22\/z\/420df.gif)\n\nPart of the reason is that I'm not that proficient with modeling, articulating, and animating. But even if I was, there's a lot of power in creating the mesh in code. So roughly, there are two things you have to do:\n\n  * Define the vertices of the mesh.\n  * Define the triangles of the mesh.\n\nIn my case, I wanted to have a snake, so it's roughly a squiggly cylinder. The way I created that was to define a spine that trails behind the head and then for each point in that spine, I define a coordinate system:\n\n  * \"Forward\" is in the direction between each point and the point in front of it.\n  * \"Up\" is away from the center of the sphere.\n  * \"Right\" is the vector cross product of the previous two.\n\nNow we can define a circle using \"Up\" and \"Right\" and then connect up neighboring circles with the appropriate triangles between circles and voila, we have a snake! Well there's a little more to it with shaping of the head and such, but that's the basic idea. You can see more details in [the code for my snake](https:\/\/github.com\/MachWerx\/SnakeOnASphere\/blob\/main\/Assets\/Scripts\/Snake.cs). Enjoy!","title":"Snake on a Sphere: Procedural Meshes","wayback_source":[]}