{"id":4708,"date":"2018-01-31T13:12:20","date_gmt":"2018-01-31T05:12:20","guid":{"rendered":"https:\/\/unitycoder.com\/blog\/?p=4708"},"modified":"2018-02-09T16:09:02","modified_gmt":"2018-02-09T08:09:02","slug":"checking-last-known-good-position-for-a-car-in-the-track","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2018\/01\/31\/checking-last-known-good-position-for-a-car-in-the-track\/","title":{"rendered":"Checking Last Known Good Position For A Car In The Track"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4709\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2018\/01\/31\/checking-last-known-good-position-for-a-car-in-the-track\/cargame1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2018\/01\/cargame1.jpg?fit=680%2C358&amp;ssl=1\" data-orig-size=\"680,358\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"cargame1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2018\/01\/cargame1.jpg?fit=680%2C358&amp;ssl=1\" class=\"alignnone size-full wp-image-4709\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2018\/01\/cargame1.jpg?resize=680%2C358&#038;ssl=1\" alt=\"\" width=\"680\" height=\"358\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2018\/01\/cargame1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2018\/01\/cargame1.jpg?resize=300%2C158&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Working on a small StuntCarRacer-inspired game with a friend.<br \/>\nSome note here about how to get car to return last known good position in the track.<\/p>\n<h3>Problems and Requirements<\/h3>\n<p>&#8211; Player gets stuck hanging in side of the track (1 or more tires hanging outside, cannot move)<br \/>\n&#8211; Player falls off from the track<br \/>\n&#8211; Should allow respawning into last known good position on the track<br \/>\n&#8211; Should reset player rotation towards correct direction<\/p>\n<h3>Solutions<\/h3>\n<ul>\n<li>\u00a0Trigger Checkpoints\n<ul>\n<li>Everytime you enter a trigger, record this as a last good position<\/li>\n<li>Should work very nicely, but either need to manually place the triggers or have some logic to automatically do that, which could become difficult with complicated tracks\n<ul>\n<li>You could manually place dummy objects in 3D modelling tool while making the track, to mark the trigger positions<\/li>\n<\/ul>\n<\/li>\n<li>This would easily solve correct rotation (take from trigger forward)<\/li>\n<\/ul>\n<\/li>\n<li>Take Closest Track Position\n<ul>\n<li>Could raycast around the car to find closest track position and lift car to the track on that point<\/li>\n<li>Cannot be used, because if you fall of the track, driving in the ground is allowed (so you could take shortcuts then)<\/li>\n<\/ul>\n<\/li>\n<li>Take Last Hit Point From Track\n<ul>\n<li>Kind of works, but often that point could be already barely touching the track and player then falls off again<\/li>\n<\/ul>\n<\/li>\n<li><span style=\"text-decoration: underline;\">Record Last Known Good Hit Point<\/span> *Currently using this method\n<ul>\n<li>Every few seconds:\n<ul>\n<li>Check that every tire hits the track<\/li>\n<li>Check that every tire slope angle is below threshold (like 10\u00b0 to avoid re-spawning in steep locations)<\/li>\n<\/ul>\n<\/li>\n<li>Only issue is that correct rotation is difficult to get, if player was driving in wrong direction, he will be respawned towards that direction also<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4710\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2018\/01\/31\/checking-last-known-good-position-for-a-car-in-the-track\/car-game-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2018\/01\/car-game-1.gif?fit=320%2C233&amp;ssl=1\" data-orig-size=\"320,233\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"car-game-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2018\/01\/car-game-1.gif?fit=320%2C233&amp;ssl=1\" class=\"alignnone size-full wp-image-4710\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2018\/01\/car-game-1.gif?resize=320%2C233&#038;ssl=1\" alt=\"\" width=\"320\" height=\"233\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working on a small StuntCarRacer-inspired game with a friend. Some note here about how to get car to return last known good position in the track. Problems and Requirements &#8211; Player gets stuck hanging in side of the track (1 or more tires hanging outside, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4709,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[420,3],"tags":[1029,1033,1034,1032,1031,1030],"class_list":["post-4708","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-unity3d","tag-car","tag-point","tag-race","tag-record","tag-respawn","tag-track"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2018\/01\/cargame1.jpg?fit=680%2C358&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-1dW","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/4708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=4708"}],"version-history":[{"count":5,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/4708\/revisions"}],"predecessor-version":[{"id":4719,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/4708\/revisions\/4719"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/4709"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=4708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=4708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=4708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}