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 /
This question was closed Sep 24, 2013 at 09:27 AM by Fattie for the following reason:

Duplicate Question

avatar image
2
Question by divyanthj · Sep 24, 2013 at 06:46 AM · positionvector3relative

How do I specify the position of one object relative to another object?

Let's say, I have a position variable

private Vector3 leaderPosition;

I want to specify another vector

private Vector3 followerPosition;

I want this followerPosition to be 5 meters away from leaderPosition and at an angle of 45 degrees behind him (diagonally behind him like a V formation).

How do I do that? How do I manually set "followerPosition" to something like

followerPosition = leaderPosition + (something);

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

2 Replies

  • Sort: 
avatar image
5
Best Answer

Answer by robhuhn · Sep 24, 2013 at 07:16 AM

To find the position you would create a vector pointing behind the leader (negative forward):

 Vector3 offset = -leader.transform.forward; //1m behind

Multiply that vector with the distance

 offset *= 5; //5m behind

Rotate the offset

 offset = Quaternion.AngleAxis(45, leader.transform.up) * offset; //45 degrees around the leaders up vector

All together

 Vector3 offset = Quaternion.AngleAxis(45, leader.transform.up) * -leader.transform.forward * distance;
 transform.position = leader.transform.position + offset;

Note: The order of multiplication is important here.

Comment
Add comment · 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
0

Answer by ScotchBunny · Sep 24, 2013 at 07:20 AM

If you use

followerPosition = leaderPosition + (something);

your follower will be in the same world direction in relation to your leader; the follower may always be south-east of the leader, for example. That is unless you take the leader orientation into your calculations.

The easier way would be to use Transform.TransformPoint. That should take care of it for you.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Translate Vector3 by Vector3 1 Answer

Vector relative to Object coordinates 1 Answer

Relative Rotation 1 Answer

Aim Down Sights Positioning Problem 1 Answer

Networking: How do I send player positions? 2 Answers


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