Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 sotrosh · Jan 14, 2018 at 10:49 PM · 2dtrigonometry

How to get new position of object based on start point, distance and angle?

How to get position based on start point, distance and angle?

Here is my implementation:

 Vector3 GetObjectPosition(Vector3 startPoint, float distance, float angle)
 {
     Vector3 newPos = new Vector3 (startPoint.x, startPoint.y);
     handObject.transform.Rotate (newPos, angle);
     newPos = handObject.transform.forward * distance;

     return newPos;
 }
 void Update () 
 {
     Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
     mousePos.z = 0;
     float angle = Vector2.Angle(this.transform.position, mousePos);

     Vector3 handPos = UpdateHandPosition (this.transform.position, 10.0f, angle);
     handObject.transform.position = handPos;
     print (handPos);
 }

As result it blinks(moves very fast) and doesn't work properly

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 fafase · Jan 14, 2018 at 11:05 PM 0
Share

Your missing a direction. You have a point but you need a direction or an initial rotation. Else, where are you heading for your distance?

Once you have direction then, take the point, extend it by distance in the direction, then rotate with Quaternion.AngleAxis or Quaternion.Euler.

avatar image sotrosh fafase · Jan 15, 2018 at 10:13 PM 0
Share

thank you for reply. please take a look to my updated topic. the start point is game object (player) and end point is mouse position

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Divinyx · Jan 14, 2018 at 11:24 PM

you can use SOH CAH TOA to get a direction vector, multiply it by distance then add it to startPoint

so your direction vector is something like Vector2(x = Mathf.Cos(angle), y = Mathf.Sin(angle))

convert your answer to degrees or keep in radians depending on how your angle is used

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 black_sheep · Jan 14, 2018 at 11:54 PM

 Vector2 GetObjectPosition(Vector2 startPoint, float distance, float angle){
 
     transform point;  //i don't remember how to rotate a vector2 so i used a transform
     point.position = startPoint;  //i'm sure there's a function to rotate a vector2
     point.rotate(angle);  //now it's pointing to the desired new location
 
     point.forward * distance;  //now walk forward that much of a distance
     //transform.forward is shorthand for (1,0,0). If your distance is 1.5f, it'll be(1.5f, 0, 0)
 
     return transform.point;
 
 }

Comment
Add comment · Show 1 · 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 sotrosh · Jan 15, 2018 at 10:10 PM 0
Share

thank you for response. I've made how you describe but doesn't work. Please check updated topic

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

144 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 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 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 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 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 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 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

Vector2.angle - how do i get if it's CW or CCW ? 5 Answers

Calculate the angle between two 3d vectors: Function always returns 89.1-89.9 1 Answer

2D character face another character 2 Answers

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

Ground checking with a frequently rotating player 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