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 jgt79 · Jul 07, 2021 at 12:36 AM · anglesvector3.distancevector mathvector3 operations

Calculate vector distance between 2 points on the same object

Hello everyone!
I'm taking some linear algebra courses and trying to apply some of my learning to a project I'm working on. I have a ship I'm animating. It has a particle system on either side. Currently I'm using the different axis to know when to enable each ps. So for example, if I turn too far on the X axis past 35 degrees, my ps on one side will enable. If I do the same on the Y or the Z the respective ps(s) will enable.

Trying to do this with vectors and angles in Editor mode so that I'm not limited to rotating in arbitrary angles. Currently, when I turn the ship it does sort of what I want. I'll turn the ship to the extreme left and the ps enables. But I practically have to flip the ship just to get it to enable. Trying to set it to my limit of 35 or 25 or whatever I choose.
Any tips are greatly appreciated.

 constant ANGLE_LIMIT = 35;
 Vector3 initialPosition  = myParticles.transform.position;
 Vector3 newPosition = myParticles.transform.position + mySpaceShip.transform.position;
 
 //Get offset distance
 target = newPosition - initialPos;
 //vector length
 distance = target.magnitude;
 //normalize
 distance = target/distance;
 
 Vector3 direction = myParticles.transform.up;
 angle = Mathf.Acos(Vector3.Dot(target, direction)*Mathf.Rad2deg;
 
 if(angle > ANGLE_LIMIT )
 {
   myParticles.Play();
 }

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 jgt79 · Jul 07, 2021 at 11:35 AM 0
Share

Ok, so walking through my code. I think I'm getting it to work. My angle always comes out to 180 by default. And then as I rotate it goes under 180 degrees. Is there a way to change that to be zero to start? That way I can say, if angle < 35 do so and so. Also, I updated my condition at the end.

 if(angle < ANGLE_LIMIT)
 {
  myParticles.Play();
 }
 else
 {
  myparticles.Stop();
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jgt79 · Jul 07, 2021 at 11:39 AM

Figured it out. I accidentally had a negative in front of the following line:

 Vector3 direction = myParticles.transform.up;
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

119 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

Related Questions

'position' is not a member of 'UnityEngine.Vector3'. 1 Answer

Change a property based on angle? 1 Answer

Brand new to Unity, trying to grasp some basic stuff related to cameras and angles 1 Answer

Calculating angles to a target and turning towards it 1 Answer

Why is rotation locking to an axis? 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