1"use strict";(self.webpackChunkrapier=self.webpackChunkrapier||[]).push([[268],{9428:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>l,default:()=>h,frontMatter:()=>s,metadata:()=>c,toc:()=>d});var r=n(4848),i=n(8453),o=n(1470),a=n(9365);const s={},l=void 0,c={id:"user_guides/bevy_plugin/collider_position",title:"collider_position",description:"The position of a collider represents its location (translation) in 2D or 3D world-space as well as its orientation (rotation).",source:"@site/docs/user_guides/bevy_plugin/collider_position.mdx",sourceDirName:"user_guides/bevy_plugin",slug:"/user_guides/bevy_plugin/collider_position",permalink:"/docs/user_guides/bevy_plugin/collider_position",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{}},u={},d=[];function p(e){const t={admonition:"admonition",code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["The position of a collider represents its location (translation) in 2D or 3D world-space as well as its orientation (rotation).\nBoth are combined in a Bevy ",(0,r.jsx)(t.code,{children:"Transform"})," component. ",(0,r.jsxs)("rust",{children:["Its translational part is represented as a vector and\nits rotational part as an unit quaternion (in 3D) or a unit complex number (in 2D). Both are\ncombined into a pose (the ",(0,r.jsx)(t.code,{children:"Pose"})," type)."]})]}),"\n",(0,r.jsx)(t.admonition,{type:"warning",children:(0,r.jsx)(t.p,{children:"Please read carefully the paragraph after the next example. It explains how the collider position (and the action of setting\nthis position) behaves differently when it is attached to a rigid-body."})}),"\n",(0,r.jsx)(t.p,{children:"It is possible to set this position when the collider is created or after its creation:"}),"\n",(0,r.jsxs)(o.A,{groupId:"dim",defaultValue:"2D",values:[{label:"Example 2D",value:"2D"},{label:"Example 3D",value:"3D"}],children:[(0,r.jsxs)(a.A,{value:"2D",children:[(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-rust",children:"/* Set the collider position when the collider is created. */\ncommands\n .spawn(Collider::cuboid(0.5, 0.5))\n .insert(Transform::from_xyz(1.0, 2.0, 0.0));\n"})}),(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-rust",children:"// Attach the collider to the rigid-body. The collider is attached as its\n// children, so the collider\u2019s `Transform` components sets its position\n// relative to the parent rigid-body.\ncommands\n .spawn((RigidBody::Dynamic, GlobalTransform::default()))\n .with_children(|children| {\n children\n .spawn(Collider::cuboid(0.5, 0.5))\n .insert(Transform::from_xyz(1.0, 2.0, 0.0));\n });\n"})})]}),(0,r.jsxs)(a.A,{value:"3D",children:[(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-rust",children:"/* Set the collider position when the collider is created. */\ncommands\n .spawn(Collider::cuboid(0.5, 0.5, 0.5))\n .insert(Transform::from_xyz(1.0, 2.0, 3.0));\n"})}),(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-rust",children:"/* Set the collider position inside of a system. */\nfn modify_collider_position(mut positions: Query<&mut Transform, With<Collider>>) {\n for mut position in positions.iter_mut() {\n position.translation.x = 2.0;\n }\n}\n"})})]})]}),"\n",(0,r.jsxs)(t.p,{children:["If a collider is ",(0,r.jsx)(t.strong,{children:"attached to a rigid-body"}),", its position is automatically updated by the physics pipeline when a\nrigid-body is moved by the physics pipeline. If a change to the rigid-body position is made by the user then the collider\nposition will be updated during the next timestep."]}),"\n",(0,r.jsxs)(t.p,{children:["Therefore, setting the ",(0,r.jsx)(t.code,{children:"Transform"})," of a collider attached to a rigid-body will modify the position of the\ncollider ",(0,r.jsx)(t.strong,{children:"relative"})," to the rigid-body it is attached to:"]}),"\n",(0,r.jsxs)(o.A,{groupId:"dim",defaultValue:"2D",values:[{label:"Example 2D",value:"2D"},{label:"Example 3D",value:"3D"}],children:[(0,r.jsx)(a.A,{value:"2D",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-rust",children:"/* Set the collider position inside of a system. */\nfn modify_collider_position(mut positions: Query<&mut Transform, With<Collider>>) {\n for mut position in positions.iter_mut() {\n position.translation.x = 2.0;\n }\n}\n"})})}),(0,r.jsx)(a.A,{value:"3D",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-rust",children:"// Attach the collider to the rigid-body. The collider is attached as its\n// children, so the collider\u2019s `Transform` components sets its position\n// relative to the parent rigid-body.\ncommands\n .spawn(RigidBody::Dynamic)\n .with_children(|children| {\n children\n .spawn(Collider::cuboid(0.5, 0.5, 0.5))\n .insert(Transform::from_xyz(1.0, 2.0, 0.0));\n });\n"})})})]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},9365:(e,t,n)=>{n.d(t,{A:()=>a});
1n(6540);var r=n(8215);const i={tabItem:"tabItem_Ymn6"};var o=n(4848);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,r.A)(i.tabItem,a),hidden:n,children:t})}},1470:(e,t,n)=>{n.d(t,{A:()=>w});var r=n(6540),i=n(8215),o=n(3104),a=n(6347),s=n(205),l=n(7485),c=n(1682),u=n(679);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:i}}=e;return{value:t,label:n,attributes:r,default:i}}))}(n);return function(e){const t=(0,c.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const i=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,r.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(i.location.search);t.set(o,e),i.replace({...i.location,search:t.toString()})}),[o,i])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:i}=e,o=p(e),[a,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[c,d]=m({queryString:n,groupId:i}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[i,o]=(0,u.Dv)(n);return[i,(0,r.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:i}),g=(()=>{const e=c??f;return h({value:e,tabValues:o})?e:null})();(0,s.A)((()=>{g&&l(g)}),[g]);return{selectedValue:a,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),b(e)}),[d,b,o]),tabValues:o}}var b=n(2303);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(4848);function x(e){let{className:t,block:n,selectedValue:r,selectValue:a,tabValues:s}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),u=e=>{const t=e.currentTarget,n=l.indexOf(t),i=s[n].value;i!==r&&(c(t),a(i))},d=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.A)("tabs",{"tabs--block":n},t),children:s.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>l.push(e),onKeyDown:d,onClick:u,...o,className:(0,i.A)("tabs__item",g.tabItem,o?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function y(e){let{lazy:t,children:n,selectedValue:o}=e;
1const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===o));return e?(0,r.cloneElement)(e,{className:(0,i.A)("margin-top--md",e.props.className)}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==o})))})}function j(e){const t=f(e);return(0,v.jsxs)("div",{className:(0,i.A)("tabs-container",g.tabList),children:[(0,v.jsx)(x,{...t,...e}),(0,v.jsx)(y,{...t,...e})]})}function w(e){const t=(0,b.A)();return(0,v.jsx)(j,{...e,children:d(e.children)},String(t))}},8453:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>s});var r=n(6540);const i={},o=r.createContext(i);function a(e){const t=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),r.createElement(o.Provider,{value:t},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.