{"id":1613,"date":"2016-08-17T03:58:23","date_gmt":"2016-08-16T19:58:23","guid":{"rendered":"http:\/\/www.clonefactor.com\/wordpress\/?page_id=1613"},"modified":"2016-08-18T02:14:20","modified_gmt":"2016-08-17T18:14:20","slug":"camerabot-position-overrider-section-setup","status":"publish","type":"page","link":"https:\/\/www.clonefactor.com\/wordpress\/unity3d-show-room\/camerabot\/camerabot-position-overrider-section-setup\/","title":{"rendered":"CameraBot Position overrider section setup"},"content":{"rendered":"<p><iframe loading=\"lazy\" title=\"CameraBot ver 3.0, position overrider section setup\" width=\"1260\" height=\"945\" src=\"https:\/\/www.youtube.com\/embed\/q-EKWA6yFZI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/p>\n<p>This session is made for anyone to override their camera position, the panel you may visualize in video will look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1615\" src=\"http:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/08\/overrider01.jpg\" alt=\"overrider01\" width=\"594\" height=\"130\" srcset=\"https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/08\/overrider01.jpg 594w, https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/08\/overrider01-300x66.jpg 300w\" sizes=\"auto, (max-width: 594px) 100vw, 594px\" \/><\/p>\n<h2>For programmers:<\/h2>\n<p>How to override\u00a0the position related to orbit camera idea position.<br \/>\nCameraBot will need the the following information,<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1616\" src=\"http:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/08\/overrider02.jpg\" alt=\"overrider02\" width=\"588\" height=\"132\" srcset=\"https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/08\/overrider02.jpg 588w, https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/08\/overrider02-300x67.jpg 300w\" sizes=\"auto, (max-width: 588px) 100vw, 588px\" \/><br \/>\nhere is the interface to implement your code.<br \/>\nInterface:\u00a0IDeaPosition<\/p>\n<pre class=\"brush:csharp\">public interface IDeaPosition\r\n{\r\n\t\/\/\/ &lt;summary&gt;Each group can only taken a position, the one with highest weight&lt;\/summary&gt;\r\n\tint GroupNumber { get; }\r\n\t\/\/\/ &lt;summary&gt;the recommand position will sent to &lt;see cref=\"CameraPivot\"\/&gt;&lt;\/summary&gt;\r\n\tVector3 ToLocalPosition { get; }\r\n\t\/\/\/ &lt;summary&gt;To define how important of this information is.&lt;\/summary&gt;\r\n\tfloat Weight { get; }\r\n\t\/\/\/ &lt;summary&gt;The information that will displayed on position overrider section.&lt;\/summary&gt;\r\n\tstring ToString();\r\n}<\/pre>\n<p>following will provide you the base class to help you implement easier.<br \/>\nbase class : IDeaPositionBase.cs<\/p>\n<pre class=\"brush:csharp\">using UnityEngine;\r\nusing Kit.Extend;\r\nusing System;\r\n\r\nnamespace CF.CameraBot.Parts\r\n{\r\n\t[RequireComponent(typeof(Preset))]\r\n\tpublic class IDeaPositionBase : MonoBehaviour, IDeaPosition\r\n\t{\r\n\t\t#region interface\r\n\t\t\r\n\t\t[SerializeField]\r\n\t\tprivate Preset m_Preset;\r\n\t\tprotected Preset preset { get { return m_Preset; } }\r\n\r\n\t\t[Header(\"Position overrider\")]\r\n\t\t[SerializeField]\r\n\t\tprivate int m_GroupNumber;\r\n\t\tpublic int GroupNumber { get { return m_GroupNumber; } }\r\n\r\n\t\t[SerializeField]\r\n\t\tprivate Vector3 m_LocalPosition;\r\n\t\tpublic Vector3 ToLocalPosition\r\n\t\t{\r\n\t\t\tget { return m_LocalPosition; }\r\n\t\t\tprotected set { m_LocalPosition = value; }\r\n\t\t}\r\n\r\n\t\t[SerializeField]\r\n\t\t[Range(0f,1f)]\r\n\t\tprivate float m_Weight = .5f;\r\n\t\tpublic float Weight { get { return m_Weight; } }\r\n\t\t#endregion\r\n\r\n\t\t#region common variables\r\n\t\t\/\/\/ &lt;summary&gt;The clone position &amp; rotation related to chase target&lt;\/summary&gt;\r\n\t\t\/\/\/ &lt;remarks&gt;Non-real chase target, it's preset's instance&lt;\/remarks&gt;\r\n\t\tprotected Transform GetChaseTarget { get { return preset.Instance.transform; } }\r\n\t\t\/\/\/ &lt;summary&gt;The offset applied on chase target&lt;\/summary&gt;\r\n\t\tprotected Transform GetChaseTargetOffset { get { return preset.Instance.GetChaseTargetOffset(); } }\r\n\t\t\/\/\/ &lt;summary&gt;The camera pivot point, position &amp; rotation&lt;\/summary&gt;\r\n\t\tprotected Transform GetCameraCurrentPivot { get { return preset.Instance.GetCameraPivot(); } }\r\n\t\t\/\/\/ &lt;summary&gt;The camera pivot point, without modify&lt;\/summary&gt;\r\n\t\tprotected Transform GetCameraIdeaPivot { get { return preset.Instance.GetCameraOffset(); } }\r\n\t\t\/\/\/ &lt;summary&gt;The location, should focus by camera&lt;\/summary&gt;\r\n\t\tprotected Transform GetCameraLookAt { get { return preset.Instance.GetCameraLookAt(); } }\r\n\t\t\/\/\/ &lt;summary&gt;The idea Camera direction&lt;\/summary&gt;\r\n\t\tprotected Vector3 GetCameraIdeaDirection { get { return GetCameraLookAt.position.Direction(GetCameraIdeaPivot.position); } }\r\n\t\t\/\/\/ &lt;summary&gt;The idea Camera distance&lt;\/summary&gt;\r\n\t\tprotected float GetCameraIdeaDistance { get { return GetCameraLookAt.position.Distance(GetCameraIdeaPivot.position); } }\r\n\t\t#endregion\r\n\r\n\t\t#region helper\r\n\t\tprotected virtual void OnValidate()\r\n\t\t{\r\n\t\t\tif (m_Preset == null)\r\n\t\t\t{\r\n\t\t\t\tm_Preset = GetComponent&lt;Preset&gt;();\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t\/\/ for debug purpose, not allow to change.\r\n\t\t\tm_LocalPosition = Vector3.zero;\r\n\t\t}\r\n\r\n\t\tprotected virtual void OnEnable()\r\n\t\t{\r\n\t\t\tm_Preset.Instance.CameraPivot.RegisterOperator(this);\r\n\t\t}\r\n\r\n\t\tprotected virtual void OnDisable()\r\n\t\t{\r\n\t\t\tm_Preset.Instance.CameraPivot.UnregisterOperator(this);\r\n\t\t}\r\n\r\n\t\tpublic override string ToString()\r\n\t\t{\r\n\t\t\treturn string.Format(\"[G:{5}][W:{0:F2}] {1} :: Pos({2:F2},{3:F2},{4:F2})\", Weight, GetType().Name, ToLocalPosition.x, ToLocalPosition.y, ToLocalPosition.z, GroupNumber);\r\n\t\t}\r\n\t\t#endregion\r\n\t}\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>And here is the sample code to achieve the basic backward obstacle avoidance, the one used in demo video.<br \/>\nSample code : BackwardObstacleAvoidance.cs<\/p>\n<pre class=\"brush:csharp\">using UnityEngine;\r\nusing Kit.Extend;\r\nnamespace CF.CameraBot.Parts\r\n{\r\n\t[RequireComponent(typeof(Preset))]\r\n\tpublic class BackwardObstacleAvoidance : IDeaPositionBase, IDeaPosition\r\n\t{\r\n\t\tpublic float m_SafeDistance = 0.2f;\r\n\t\t\r\n\t\t\/\/\/ &lt;summary&gt;Ignore nothing by default, recommand ignore chase target's layer&lt;\/summary&gt;\r\n\t\tpublic LayerMask m_IgnoreLayerMask = 1;\r\n\r\n\t\tvoid FixedUpdate()\r\n\t\t{\r\n\t\t\tBackwardRaycast();\r\n\t\t}\r\n\r\n\t\tprivate void BackwardRaycast()\r\n\t\t{\r\n\t\t\tRaycastHit hit;\r\n\t\t\tif (Physics.Raycast(\r\n\t\t\t\t\tGetCameraLookAt.position,\r\n\t\t\t\t\tGetCameraIdeaDirection,\r\n\t\t\t\t\tout hit,\r\n\t\t\t\t\tGetCameraIdeaDistance,\r\n\t\t\t\t\t~m_IgnoreLayerMask,\r\n\t\t\t\t\tQueryTriggerInteraction.UseGlobal))\r\n\t\t\t{\r\n\t\t\t\tToLocalPosition = GetCameraIdeaPivot.InverseTransformPoint(hit.point.PointOnDistance(-GetCameraIdeaDirection, m_SafeDistance));\r\n\t\t\t\tDebug.DrawLine(GetCameraLookAt.position, hit.point, Color.red, 0.01f);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tToLocalPosition = Vector3.zero;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n<\/pre>\n<p>by following the interface to implement\u00a0your code, we are able to override the orbit camera position to anywhere, problem is how to achieve your\u00a0ideas.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1617\" src=\"http:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/08\/overrider03.jpg\" alt=\"overrider03\" width=\"573\" height=\"473\" srcset=\"https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/08\/overrider03.jpg 573w, https:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/08\/overrider03-300x248.jpg 300w\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This session is made for anyone to override their  &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1250,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"full-width-page.php","meta":{"footnotes":""},"class_list":["post-1613","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/pages\/1613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1613"}],"version-history":[{"count":0,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/pages\/1613\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/pages\/1250"}],"wp:attachment":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}