Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Kastt · Nov 02, 2011 at 01:33 AM · rigidbodypositionforce

How to find the relative position of a side of an object

I have a cube and I would like to use addforceatposition and apply this position to the center of a particular cube face in order to make that face turn to face the pulling object.

I do not understand however how to calculate the position of the cubes side for the position attribute of the function. Is this suppose to be a relative position, or am I suppose to get the center of the cube from its position, and then add 1/2 its dimensions to that point to get the particular side while accounting for rotation? Does Unity have some means of calculting the position of that side relatively and then converting it to world coordinates?

Thank you for your help.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by aldonaletto · Nov 02, 2011 at 01:58 AM

A simple way to find the center of a cube face is to use the local references transform.up, right and forward. They are unit vectors, thus you can multiply them by the cube size / 2 and add to the cube position, as you suspected. For instance:

 front face center: transform.position + transform.forward * cubeSize/2;
 back face center: trasnform.position - transform.forward * cubeSize/2;
 left face center: transform.position - transform.right * cubeSize/2;
 bottom face center: transform.position - transform.up * cubeSize/2;

and so on. You don't have to worry about rotation, since these local vectors follow the cube orientation.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ziplock9000 · Jul 03, 2017 at 12:44 PM 0
Share

Doesn't this assume the objects pivot/origin is in the center of the object?

avatar image aldonaletto Ziplock9000 · Jul 04, 2017 at 12:54 AM 0
Share

Yes, and that's true for cube primitives in Unity. I suspect that Unity sets the pivot of any mesh in the middle of the $$anonymous$$ and max points. Let's suppose that a given mesh has $$anonymous$$ = (-1,0,0) and max = (1,1,0.6): its pivot should then be at ($$anonymous$$+max)/2, what means (0.0,0.5,0.3)
As @Bunny83 said below, the pivot is always at the model origin - I've got confused by the Pivot/Center button in the Editor, which was set to Center (shame on me!).

avatar image Bunny83 aldonaletto · Jul 04, 2017 at 04:32 AM 0
Share

No, Unity doesn't "place" the pivot anywhere. The pivot is not a "special location". It's always (0,0,0) in local space. It's simply the origin of the objects local space. $$anonymous$$ost modelling tools have a "move pivot" function. However what actually happens when you move the pivot from the center to the bottom is that all vertices are actually moved upwards. The vertices are defined in localspace.

The default cube primitive simply has it's vertices defined around the origin. Though custom meshes could have it's origin anywhere. For human models it's quite common to place it at the bottom.

avatar image Bunny83 Ziplock9000 · Jul 04, 2017 at 04:37 AM 0
Share

Note only that but also the cube need to be aligned with the local coordinate system. This is usually the case for cubes, but it's possible to define the cube so it stands on a corner when not rotated. In this case the local axes wouldn't match with the cube faces.

avatar image Ziplock9000 · Jul 04, 2017 at 08:02 AM 0
Share

The reason I ask is because I've just written some routines for aligning and snapping objects together that are from arbitrary sources like $$anonymous$$agicaVoxel, Blender, VoxelShop and they have to take into account that the origin is often not in the center or 0,0,0 (local).

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem stopping rigid body after adding a force 0 Answers

Making something move relative to something else, but slower/shorter ? 2 Answers

relative velocity of rigidbody according to rotation... 1 Answer

Prevent Rigidbody from Climbing Steep Slopes using Forces (C#) 0 Answers

Objects continue to have force applied after escaping force range 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges