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
0
Question by eddyzy · Feb 11, 2014 at 07:12 PM · vector3directionpointmiddle

How can you get a point on a direction,which is defined by 2 Vector 3s

Hi to all. I`m making a RTS Game an i`ve encountered a problem.

I have the position of two units(Vector3)and i want to find the point with one unit closer to the units positions from the middle point;

I know how to calculate the middle point, but HOW do i calculate the points one unit towards the units position. alt text

I`m trying to find point1 and point2;

example.png (20.5 kB)
Comment
Add comment · Show 1
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 iamvishnusankar · Feb 11, 2014 at 07:21 PM 0
Share

Use eqn of line in 3D

2 Replies

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

Answer by robertbu · Feb 11, 2014 at 07:28 PM

Given two Vector3 name unit1 and unit2:

 var dir = unit2 - unit1;  
 var middle = unit1 + dir * 0.5;
 var point1 = middle - dir.normalized * dist;
 var point2 = middle + dir.normalized * dist;

Where 'dist' is the distance from the middle.

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
1

Answer by FrimaMickD · Feb 11, 2014 at 07:37 PM

This is simple.

Let's say you have your vector from Unit1 to Unit2 :

  Vector3 unit1To2 = unit2.transform.position - unit1.transform.position;

You can have the length of that vector by doing this:

  float vLen = unit1To2.magnitude;

You can have the unit vector (of length 1) by doing the Normalize operation:

 unit1to2.Normalize();

You can find the middle point doing so, assuming unit1to2 has been normalized.

 Vector3 middlePoint = unit1.transform.position + (unit1to2 * vLen /2.0f);

You can also directly have point 1 and 2 by doing this:

 Vector3 point1= unit1.transform.position + (unit1to2 * ((vLen /2.0f) - 1.0f ));
 Vector3 point2= unit1.transform.position + (unit1to2 * ((vLen /2.0f) + 1.0f ));

For this kind of problem you really have to familiarize with vector math, magnitude (length), Normal vectors, etc.

Doing a RTS without this knowledge will be impossible, but I wish you luck learning :)

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.

Follow this Question

Answers Answers and Comments

20 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 avatar image avatar image avatar image

Related Questions

how to find direction between two points 2 Answers

Rotation of object placed in the middle point between two points? 0 Answers

Find a point between 2 vectors for a specific Y 1 Answer

Why in Unity is no separate Point and Vector class ? 1 Answer

Move point in the direction of another 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