• 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
0
Question by KennSan · May 28, 2011 at 04:45 PM · localposition

Set an objects position from the local position of another

I have two objects, one on each side facing one another - now I need the camera to sit in front of the object. However I cannot get the camera to sit in front of the cameras local object. Here's what I'm currently using:

target.transform.localPosition+Vector3(distanceFromObject-0.1, distanceFromObject, -distanceFromObject);

I'm guessing that it's to do with the Vector3 working in global space as opposed to local- any way I can overcome this issue?

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
1
Best Answer

Answer by Henrique Vilela · May 28, 2011 at 05:17 PM

The Transform class has 4 methods to do this kind of transformation:

  • TransformDirection Transforms direction from local space to world space.

  • InverseTransformDirection Transforms a direction from world space to local space. The opposite of Transform.TransformDirection.

  • TransformPoint Transforms position from local space to world space.

  • InverseTransformPoint Transforms position from world space to local space. The opposite of Transform.TransformPoint.

source: http://unity3d.com/support/documentation/ScriptReference/Transform.html

Comment
Add comment · Show 2 · 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 KennSan · May 29, 2011 at 12:38 AM 0
Share

Thanks for the point in the right direction. For those who stumble across this in the future looking for the answer I used:

target.transform.localPosition+target.transform.InverseTransformDirection(0.1, distanceFromObject, -distanceFromObject)+Vector3(0,0,-distanceFromObject);

the localPosition to begin at the targets position, the InverseTransformDirection sets a Vector3 in local direction (so it is in front of the object), then the standard Vector3 to add to this location in world co-ordinates (so it's on the same side of each character.)

avatar image lPVDl · Aug 08, 2014 at 02:31 AM 0
Share

Thanks a lot!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

translate from JavaScript to C#? 3 Answers

[C#]Mathf.Clamp glitching between two local positions. 0 Answers

Get Local Mouse Position from the center of the Gameobject clicked on 2 Answers

Adding a local position with InverseTransformPoint works in z axis, but inverts in x axis 0 Answers

Setting Position Relative to Object 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