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 24, 2019 at 08:12 AM · 3dvector3velocityrigidbody.addforcetransform.forward

how to find forwards,right,up component of a velocity

I have the velocity of a 3d ball but need to have a way of getting the right component of it, like you do with transform.right ect. I need to add it as a force to my rigidbody. Here's a quick diagram to show you: alt text

@tormentoarmagedoom @Pangamini Just ask me if you have anything else that you need in order to work this out.

ball-diagram.jpg (14.9 kB)
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 tormentoarmagedoom · May 24, 2019 at 09:01 AM 0
Share

Arrived late :D

2 Replies

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

Answer by Pangamini · May 24, 2019 at 08:28 AM

Ahh ok I see, you want the direction, not the velocity component. Well the tricky thing is, there are infinitely many vectors that are perpendicular to the velocity vector.

You can get what you want by doing Vector3.Cross(), the cross product of two vectors is always perpendicular to both of them (if they are not parallel, of course). So if you do Vector3.Cross(velocity, Vector3.up) the result should be parallel to the ground and point to the side of the ball (either left or right, depends on the order of vectors in the cross). Just keep in mind that this will fail if the ball moves straight up or down (result will be a zero vector)

Comment
Add comment · Show 7 · 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 Pangamini · May 24, 2019 at 08:29 AM 0
Share

Also, if the velocity is zero, the result will be zero

avatar image BluePyramid · May 24, 2019 at 08:34 AM 0
Share

Thanks would there be a simpler way to deter$$anonymous$$e whether it would go left or right?

avatar image Pangamini BluePyramid · May 24, 2019 at 08:36 AM 0
Share

Well, it will always go either left or right - so just try it and see where does it go :) I am not sure about the order of cross operands now.

avatar image BluePyramid Pangamini · May 24, 2019 at 08:53 AM 0
Share

ok! ........

Show more comments
avatar image BluePyramid · May 24, 2019 at 10:09 AM 0
Share

Ok. Which ones would you cross to get the forwards or would that simply be the velocity itself?

@Panga$$anonymous$$i

avatar image Pangamini BluePyramid · May 24, 2019 at 10:11 AM 0
Share

well depends on how do you define 'forwards'. If you want a 'forward' that's also parallel to the ground, then, well, think. Cross gives you avector perpendicular to both operands. It would be possible to just take the velocity, set Y to zero, and normalize - or, take your RIGHT vector, cross it with VEctor3.UP - giving you a vector perpendicular to those two - a forward that's parallel to the ground

avatar image
1

Answer by Hellium · May 24, 2019 at 08:32 AM

As indicated by Pangamini, having a "right" vector is not that obvious because there are technically and infinite number of possible vectors. Supposing you want a vector which is perpendicular to the velocity vector, and the most perpendicular to the Vector3.up, you can do the following.

     Vector3 forward = velocity.normalized;
     Vector3 v = Mathf.Abs( Vector3.Dot( forward, Vector3.up ) ) > 0.95f ?
                              Vector3.forward :
                              Vector3.down;
     Vector3 right = Vector3.Cross( forward, v );
     Vector3 up = Vector3.Cross( forward, right );

The problem mentionned by Pangamini is handled by the ternary operator.

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

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

Trouble with rb.Addforce(transform.foreward) 3 Answers

Calculate Angular Velocity to Match Remote Position 0 Answers

how to limit horizontal input when jumping 1 Answer

Jumping with Rigidbody.AddForce not working? 1 Answer

Slow falling when using Rigidbody set velocity as playercontroller 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