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 BluePyramid · May 22, 2019 at 07:31 AM · rotationdirectiontransform.forward

How to find the direction an object is flying in?

I have a golf ball that is spinning on all the different axis and I need to find out which angle it is heading in on the Y axis. Transform.forward doesn't work because it is spinning.

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 Pangamini · May 22, 2019 at 09:23 AM 0
Share

What do you mean by "heading"? It implies it has some velocity, right? In that case, isn't the velocity vector of the object your direction of movement?

avatar image BluePyramid Pangamini · May 22, 2019 at 12:33 PM 0
Share

yes .......

2 Replies

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

Answer by Pangamini · May 22, 2019 at 09:28 AM

Ah now I understand the problem By 'angle on the Y axis', you mean, like, the azimuth. First, the rotation of the ball has nothing to do with its movement. The ball has a velocity (either from rigidbody, or from your own script), which I will assume is a world-oriented Vector3. If that is the case, and what you want to calculate is the azimuth, then you need to: 1. Take the X and Z elements of the velocity (the Y element doesn't affect the azimuth, right?) 2. Feed it to the Mathf.Atan2. It will calculate an angle of a vector from the X+ axis in CCW direction. See the docs for that function. The result is in radians, make sure you convert to the units you need.

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 tormentoarmagedoom · May 22, 2019 at 07:48 AM

Hello.


[Edited] : Pangamini comment is correct, is a better (less cpu cost) way.


Maybe there is some command or fucntion to know it.

But if you dont find any, you can always make a "trick":

In a script, during the same frame...:

Create a emptyobject, child of the ball with localposition and localrotation of 0.

Move this emptyobjc in Y axis of its local coords. Then, unparent it from the ball.

Then calculate the vector (emptyobj position - ball position).

This vector is the Y direction of the ball.

Bye!

Comment
Add comment · Show 10 · 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 BluePyramid · May 22, 2019 at 07:49 AM 0
Share

thank you!!!

avatar image BluePyramid · May 22, 2019 at 08:37 AM 0
Share

how would I create the empty gameobject as a child in script?

avatar image tormentoarmagedoom BluePyramid · May 22, 2019 at 09:29 AM 0
Share

Come on max... make little research... its simple. (you can always Instantiate a prefab to do it)

avatar image BluePyramid tormentoarmagedoom · May 22, 2019 at 09:39 AM 0
Share

sorry i'm pretty new to the scene and only an 11 year old kid

Show more comments
avatar image Pangamini · May 22, 2019 at 09:17 AM 1
Share

Creating a gameObject and destroying it immediately for a simple calculation doesn't sound like a good idea You can calculate the exact same thing by taking the ball's transform

 Vector3 worldDirection = ball.transform.TransformDirection(localDirection)

avatar image BluePyramid Pangamini · May 22, 2019 at 09:37 AM 0
Share

that's what I thought, destroying and recreating it would possibly be demanding on the performance of the device

avatar image Pangamini BluePyramid · May 22, 2019 at 09:40 AM 0
Share

$$anonymous$$ostly I try to avoid ANY kind of memory allocation in the updates ( or anywhere possible) because unity's garbage collector sucks, and it causes the fps hiccups once a while. The more memory garbage, the more often it happens. That's why Unity keeps adding methods that, ins$$anonymous$$d of returning an array of something (Eg. raycast hits) they let you provide the buffer to be filled with data ins$$anonymous$$d. Ideally, you'd check the profiler and see no allocations over time, except for when you are really creating new objects in the scene. And even there, It's often good to pool and reuse the objects that are spawned frequently (projectiles, hit particles, etc), not because of the object creation cost, but the memory garbage collection cost.

Show more comments

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

142 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

Related Questions

transform.forward not working correctly? 1 Answer

Vector3.SignedAngle wrong direction when crossing the 0 point 1 Answer

Objects Rotation to modify Objects transform velocity/Direction of travel 1 Answer

Rotate player in movement direction 1 Answer

How to make a player rotate in a direction with a slope of the ground. 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