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 unity_UxM4JsRGhmfbgw · Jan 26, 2021 at 09:30 AM · vector3vector3.distancevector3.angle

How to get left forward and right forward vector position from player of distance 10 and with angle 15 from player position?

I am new to unity and Vector math. I am trying to calculate the forward left and forward right vector position of distance 10 and angle of 15 degrees from the player position.

alt text

A = player position

B = Forward Right

C = Forward Left

how to calculate B and C with every movement of player?

equilateraltriange-59da5d1d4f795a78874e1f51f9a4898.jpg (4.7 kB)
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

· Add your reply
  • Sort: 
avatar image
1

Answer by jackmw94 · Jan 26, 2021 at 10:48 AM

Assuming the player's transform is facing forward, playerTransform.forward will be the vector stating that forward direction.

This will be a unit vector so its magnitude will be 1, to make it 10 we can multiply it by 10.

Now to rotate it. When rotating things, use quaternions - they sound scary (and kind of are) but as long as you use their functions and ignore what's going on underneath they're pretty sweet. So to rotate your scaled forward vector around the up axis we would write:

 var scaledForward = playerTransform.forward * 10f;
 var leftRotated = Quaternion.AngleAxis(-15f, playerTransform.up) * scaledForward;
 var rightRotated = Quaternion.AngleAxis(15f, playerTransform.up) * scaledForward;


These leftRotated / rightRotated vectors are the offsets from the player's position. To get the actual positions of B and C you can add these to the player's position:

 var positionB = playerTransform.position + leftRotated;
 var positionC = playerTransform.position + rightRotated;


Hope this helps, feel free to reply here if there's anything you don't understand! :)

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 FeedMyKids1 · Jan 26, 2021 at 10:59 AM

 [SerializeField] float distForward = 10f;
     [SerializeField] float arcAngle = 15f;
 
     private void OnDrawGizmosSelected()
     {
         Vector3 forward = transform.position + transform.TransformDirection( Vector3.forward * distForward);
         
         Quaternion leftRot = Quaternion.AngleAxis(-arcAngle, transform.up);
         Quaternion rightRot = Quaternion.AngleAxis(arcAngle, transform.up);
 
         Vector3 forwardToLeft = leftRot * forward;
         Vector3 forwardToRight = rightRot * forward;
 
         Gizmos.color = Color.red;
         Gizmos.DrawLine(transform.position, forward);
 
         Gizmos.color = Color.blue;
         Gizmos.DrawLine(transform.position, forwardToLeft);
 
         Gizmos.color = Color.green;
         Gizmos.DrawLine(transform.position, forwardToRight);
 }
 
 Put this on the player to visualize where those points are. 
 Blue is left, Green is right. 
 
 transform.forward may not inherently work, that's why you see the transform.TransformDirection call. It will convert world space to local.
 
 You can adjust the distance forward and the angle in the inspector. Just put this into a script on the player.
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

141 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

Related Questions

Having problem with Vector3.distance 1 Answer

GameObject's transform in Vector3 1 Answer

What is the 3rd point of Vector3.Angle ? 1 Answer

Vector3.Distance is acting erratically 2 Answers

Can't change vector direction 0 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