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 superflyninja · Mar 30, 2015 at 08:50 AM · vector3translatetrigonometry

How to get point a set distance along a direction

Hi all, I have an angle. And I have a distance from an origin point.( in 3d but only on two axes - game will be top down) What I want is to find another point that is the distance in the direction of the angle. Im sure this is super easy but Im just not getting it right. I had been trying to work out the position values using Pythagoras' theorem but no joy.

Comment
Add comment · Show 6
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 superflyninja · Mar 30, 2015 at 11:12 AM 0
Share

anybody? anything to try?

avatar image meat5000 ♦ · Mar 30, 2015 at 11:21 AM 0
Share

Show us what you've tried

avatar image superflyninja · Mar 30, 2015 at 11:32 AM 0
Share

ok since I have the distance(hypotenuse) and the angle, ive tried : adjacent = hypotenuse ($$anonymous$$athf.Cos(angle)); opposite = hypotenuse ($$anonymous$$athf.Sin(angle));

I then add the opposite value to the z component and adjacent value to the x component of the position vector of the object.

avatar image meat5000 ♦ · Mar 30, 2015 at 11:39 AM 0
Share

If you normalise a Vector you get the Unit Vector, which is a directional vector 1 unit in magnitude. You can multiply this by some magnitude to point further along that direction. The vector itself always points the same relative direction.

Can you do anything with this snippet of info?

It would help to edit your question to provide some context. There are a few ways to do this and I guess it depends on what exactly you are trying to do.

avatar image superflyninja · Mar 30, 2015 at 11:57 AM 0
Share

What Im trying to do is generate a regular polygon around a central point. The reg polygon shape is assembled using cubes.That part works just dandy. I can generate anything from a triangle to a 16 sided poly and beyond. But the point I start generating is user set. I want it to construct itself around the player position (with the player being central). So the distance Im talking about is the radius of the regular poly. I use this formula :

 radius = (wallLength)/(2 * ($$anonymous$$athf.Sin(180/numWalls)))

To get the angle I use 360/numWalls So the point Im trying to find is (on a square for example) the top left corner.

Here is a webplayer of the tunnel that is generated https://t.co/kT7HwTZUDt

So the camera is central and facing down. so the y values in the positions are handled, its just x,z i need to get

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MakakWasTaken · Mar 30, 2015 at 11:35 AM

You could try this:

         float angle = 3.0f;
         Quaternion Rot = Quaternion.AngleAxis(angle,Vector3.forward);
         Vector3 Dir = Rot * Vector3.forward;
         Vector3 WorldDir = transform.TransformDirection(Dir);
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 superflyninja · Mar 30, 2015 at 11:41 AM 0
Share

would that result in a specific point though? would I need to multiply WordDir by the distance(distance I want the point to be from the origin)

avatar image MakakWasTaken · Mar 30, 2015 at 11:42 AM 0
Share

Yes, you should multiply it by the desired distance from the origin.

avatar image superflyninja · Mar 30, 2015 at 12:30 PM 0
Share

Hmmm not sure Im fully clear... So for example, the distance is 4 and the angle is 60degrees and the camera is at origin. What would the C# look like?

avatar image MakakWasTaken · Mar 30, 2015 at 12:34 PM 0
Share
          float angle = 60.0f;
          Quaternion Rot = Quaternion.AngleAxis(angle,Vector3.forward);
          Vector3 Dir = Rot * (Vector3.forward * 4);
          Vector3 WorldDir = Camera.main.transform.TransformDirection(Dir);

This should do it.

avatar image superflyninja · Mar 30, 2015 at 02:05 PM 0
Share

thanks! ill give it a go later. I need to get my head around the 3d positioning stuff a bit.

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

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

Related Questions

Projectile speed changing by distance to target 1 Answer

Find third point resulting in a right angle triangle with 2 known points 1 Answer

Translate issue with Vector3.MoveTowards 1 Answer

Projectile reflection 1 Answer

How to teleport gameobject (instantly change transform.position) 3 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