{"id":8746,"date":"2015-05-31T14:25:37","date_gmt":"2015-05-31T13:25:37","guid":{"rendered":"http:\/\/www.keris-studio.fr\/blog\/?p=8746"},"modified":"2015-05-31T14:32:04","modified_gmt":"2015-05-31T13:32:04","slug":"unity-3d-opening-doors-ouvrir-les-portes","status":"publish","type":"post","link":"https:\/\/www.keris-studio.fr\/blog\/?p=8746","title":{"rendered":"Unity 3D &#8211; opening doors &ndash; ouvrir les portes"},"content":{"rendered":"<p align=\"justify\">First create a little set, where you can find a wall with a door in it.<br clear=\"all\" \/><em>D\u2019abord il faut cr\u00e9er un petit d\u00e9cor avec un mur perc\u00e9 d\u2019une porte.<\/em><\/p>\n<p align=\"justify\"><a href=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/clip_image00259.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"clip_image002\" src=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/clip_image002_thumb56.jpg\" alt=\"clip_image002\" width=\"605\" height=\"326\" border=\"0\" \/><\/a><!--more--><\/p>\n<p align=\"justify\">The door is made from a cube. So the pivot is right in the middle of the cube. So, the door should rotate around its pivot, jute like if it was spinning.<br clear=\"all\" \/><em>La porte est faite \u00e0 partir d\u2019un cube. Or, le pivot est juste au milieu du cube. La porte va donc tourner autour de son axe m\u00e9dian.<\/em><\/p>\n<p align=\"justify\">Create an Empty Object and place it where the hinges are. Parent this empty with the door.<br clear=\"all\" \/><em>Cr\u00e9er un Empty Object et le placer \u00e0 la place des gonds. Puis parenter l\u2019empty avec la porte.<\/em><\/p>\n<p align=\"justify\"><a href=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/clip_image00450.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"clip_image004\" src=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/clip_image004_thumb46.jpg\" alt=\"clip_image004\" width=\"605\" height=\"219\" border=\"0\" \/><\/a><\/p>\n<p align=\"justify\">Create un collider with a cube.<br clear=\"all\" \/><em>Cr\u00e9er un collider avec un cube.<\/em><\/p>\n<p align=\"justify\"><a href=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/clip_image00639.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"clip_image006\" src=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/clip_image006_thumb39.jpg\" alt=\"clip_image006\" width=\"605\" height=\"361\" border=\"0\" \/><\/a><\/p>\n<p align=\"justify\">Remove the Mesh Renderer tick and declare it as trigger<br clear=\"all\" \/><em>Enlever la coche Mesh Renderer et cocher \u00ab is trigger \u00bb.<\/em><\/p>\n<p align=\"justify\"><a href=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/clip_image0074.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"clip_image007\" src=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/clip_image007_thumb4.png\" alt=\"clip_image007\" width=\"396\" height=\"509\" border=\"0\" \/><\/a><\/p>\n<p align=\"justify\">Apply the following stript on the Hinge<br clear=\"all\" \/><em>Appliquer le script suivant sur l\u2019axe (le Empty Object qui sert d\u2019axe).<\/em><\/p>\n<p align=\"justify\">Script comes from : <em>Le script vient de :<\/em><\/p>\n<p align=\"justify\"><a href=\"http:\/\/answers.unity3d.com\/questions\/294194\/how-to-make-a-solid-door-open-and-close.html\">http:\/\/answers.unity3d.com\/questions\/294194\/how-to-make-a-solid-door-open-and-close.html<\/a> (thanks !!)<\/p>\n<pre lang=\"languagestring\">\/*\r\n      Instruction:\r\n     create a cube to use as hinge put where is needed, the withe cube\r\n     press f to meet it position\r\n     create a cube to use as door end re-size, the brown cube\r\n     centre the hinge at the door__________________________pic door1\r\n     parent the hinge at the door\r\n     \r\n     in the inspector, centre the collider at the door re size as your need \r\n     and enable trigger___________________________________pic door2  \r\n     \r\n     Assign this script at the hinge \r\n      \r\n     Press \"f\" to open and  close the door\r\n     if whant change in, if(Input.GetKeyDown(\"f\")at line 46\r\n     Make sure the main character is tagged \"player\"\r\n     when all work can remove Mash render and Mash Filter \r\n     *\/ \r\n \r\n \r\n \r\n \r\n     \/\/ Smothly open a door\r\n     var smooth = 2.0;\r\n     var DoorOpenAngle = 90.0;\r\n     var DoorCloseAngle = 0.0;\r\n     var open : boolean;\r\n     var enter : boolean; \r\n     \/\/Main function\r\n      function Update ( ){\r\n        \r\n      if(open == true){ \r\n        var target = Quaternion.Euler (0, DoorOpenAngle, 0);\r\n          \/\/ Dampen towards the target rotation\r\n           transform.localRotation = Quaternion.Slerp(transform.localRotation, target,\r\n           Time.deltaTime * smooth);\r\n      }\r\n     \r\n      if(open == false){\r\n        var target1 = Quaternion.Euler (0, DoorCloseAngle, 0);\r\n          \/\/ Dampen towards the target rotation\r\n           transform.localRotation = Quaternion.Slerp(transform.localRotation, target1,\r\n        Time.deltaTime * smooth);\r\n      }\r\n     \r\n       if(enter == true){\r\n         if(Input.GetKeyDown(\"f\")){\r\n      open = !open;\r\n         }\r\n      }\r\n       \r\n     }\r\n     \r\n     \/\/Activate the Main function when player is near the door\r\n     function OnTriggerEnter (other : Collider){\r\n     \r\n      if (other.gameObject.tag == \"Player\") {\r\n      (enter) = true;\r\n      }\r\n     }\r\n     \r\n     \/\/Deactivate the Main function when player is go away from door\r\n     function OnTriggerExit (other : Collider){\r\n     \r\n      if (other.gameObject.tag == \"Player\") {\r\n      (enter) = false;\r\n      }\r\n     }\r\n\r\n<\/pre>\n<p align=\"justify\"><strong>Test : when pressing f key the door opens or closes.<\/strong><br clear=\"all\" \/><strong><em>Tester : en appuyant sur la touche f, la porte s\u2019ouvre ou se ferme.<\/em><\/strong><\/p>\n<p align=\"justify\"><a href=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/image598.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.keris-studio.fr\/blog\/wp-content\/image_thumb592.png\" alt=\"image\" width=\"1024\" height=\"608\" border=\"0\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>First create a little set, where you can find a wall with a door in it.D\u2019abord il faut cr\u00e9er un petit d\u00e9cor avec un mur perc\u00e9 d\u2019une porte.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,14,8,205],"tags":[277,140],"class_list":["post-8746","post","type-post","status-publish","format-standard","hentry","category-3d","category-conception","category-methodologie","category-unity-2","tag-script","tag-unity"],"_links":{"self":[{"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8746"}],"version-history":[{"count":7,"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8746\/revisions"}],"predecessor-version":[{"id":8753,"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8746\/revisions\/8753"}],"wp:attachment":[{"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.keris-studio.fr\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}