• 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
2
Question by aanimation · May 05, 2015 at 09:50 PM · vector3.position

find vector3

alt text

anyone can help me?

how to find vector3 value about this pict?

how-to-find.jpg (21.3 kB)
Comment
Add comment · Show 2
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 savlon · May 05, 2015 at 09:54 PM 0
Share

Isn't that just the direction multiplied by the range? Do you know how to get the direction vector?

avatar image Bunny83 · May 05, 2015 at 10:08 PM 1
Share

+1 Just for having a great image in the question ^^.

Even though questions like this has been asked several times before, we're ultimately here to collect good questions and good answers.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by NoseKills · May 05, 2015 at 09:57 PM

             float range = 3f;
             Vector3 Tp = target.transform.position;
             Vector3 Pp = player.transform.position;
 
             // vector from target to player
             Vector3 targetToPlayer = Pp - Tp;
             // vector with same direction as "targetToPlayer", but length of "range"
             Vector3 targetToPlayerWithRangeLength = targetToPlayer.normalized * range;
 
             // start from target and come towards player the "range amount".
             Vector3 positionOfSpot = Tp + targetToPlayerWithRangeLength;
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 Sprawl · May 05, 2015 at 09:57 PM

First, you need to get the vector3 of the orientation towards the target. After that, you will need to get only the part up to the circle around the target.

To get the orientation, simply substract them from one another :

 Vector3 orientation = (target.position - player.position);

Afterwards, substract the value of the range from it, like so :

 //Get the orientation of previously found vector
 Vector3 GreenVector = orientation.normalized;
 
 //Get the lenght of the previous vector minus the range
 GreenVector = GreenVector * (orientation.magnitude - range); 


That should get you the green vector on the picture.

EDIT: Now, if you want the position of the point, simply add the player's position to GreenVector.

 Vector3 DesiredPosition = PlayerPosition + GreenVector;

Comment
Add comment · Show 3 · 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 Bunny83 · May 05, 2015 at 10:00 PM 0
Share

Well if you swap your points you don't need that orientation.magnitude thing ^^. See Nose$$anonymous$$ills answer

It's always good to have the head-$$anonymous$$us-tail in $$anonymous$$d.

avatar image Bunny83 · May 05, 2015 at 10:05 PM 0
Share

btw: your "myAnswer" vector just contains a relative vector with the lenth of the distance between the player and the target $$anonymous$$us the range. To get the actual point you have to add the player's position as well.

avatar image Sprawl · May 06, 2015 at 12:05 AM 0
Share

You're right about that last part, the questions isn't really precise about what it asks. I'll modify it so it gives the position as well.

avatar image
0

Answer by aanimation · May 06, 2015 at 12:43 PM

             if(hit.collider.gameObject.tag == "Tower"){
                 Transform tower = hit.collider.gameObject.transform;

                     Vector3 Tp = tower.position;
                     Vector3 Pp = this.gameObject.transform.position;
                     
                     Vector3 targetToPlayer = Pp - Tp;
                     Vector3 targetToPlayerWithRangeLength = targetToPlayer.normalized * rangeShoot;
                     
                     Vector3 positionOfSpot = Tp + targetToPlayerWithRangeLength;
                     target.position = positionOfSpot;

                     Instantiate(marker, positionOfSpot, Quaternion.identity);
                 }}

hi All, thanks for responses, working perfect :)

terimakasih (bahasa)

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

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

6 People are following this question.

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

Related Questions

How to find IndexOf vector3 List ? position search 2 Answers

What is wrong with my movement code 1 Answer

How would I clamp a balance board? Mathf.clamp does not work! 1 Answer

Passing Vector3 to Method ? 2 Answers

C# trying to move a object 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