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 Karsnen_2 · Nov 28, 2012 at 07:15 PM · rigidbodyiosvector3force

Find the Vector to divert from colliding?

Hello Devs,

I have a rigidbody which is applied force on it and it tends to move around the wold space. Now at times, it might reach a circular object and I do not want to hit the collider. Lets say that, that circular object (Collider) is a static object and the rigidbody is always on the movement.

Pictorial Representation :

alt text

The above image can also be found here.

Main Issue:

Now the problem is I do not want to change the force which is already being applied. I just want to add a force that would divert the rigidbody from colliding. For example, lets say a rigidbody is moving forward, I think that if we apply vector3.right or vector3.left to divert it.

Thank you.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kaolas · Nov 30, 2012 at 06:44 PM

It sounds like you want to get the cross product of the current vector. The Vector3.Cross() function will get the perpendicular 3rd vector to any given two vectors you provide it. So for example:

 var diversionVector = Vector3.Cross(transform.forward, transform.up);

The diversionVector is a perpendicular vector that you could use to apply additional force to divert your object. You can negate the diversionVector to make it go the opposite direction if necessary (i.e. left instead of right).

Comment
Add comment · Show 2 · 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 Karsnen_2 · Nov 30, 2012 at 07:57 PM 0
Share

kaolas -> Thank you. When you say transform.forward does it mean local forward or global forward? I also assume that the transform is the rigidbody.

Thank you.

avatar image kaolas · Nov 30, 2012 at 08:57 PM 0
Share

"transform.forward" would be the current forward vector for your object based on its current rotation, so that would translate to the "local" forward. It isn't necessarily the same as Vector3.forward (though it could be). This is all, of course, assu$$anonymous$$g your object rotates to face the direction it's traveling. If it isn't, you could always use the direction of the force being applied to the object which is pushing it toward the collision that you want to avoid. Using that vector as your "forward", the cross product would provide you with a perpendicular vector to the force ins$$anonymous$$d of the direction the object is facing.

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

11 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to compute the change in vector when it's referential vector changes? 0 Answers

Performance Question on Kinematic Rigidbodies 1 Answer

Force iOS first person to move slightly when player is not moving it? 1 Answer

Apply vertical Force then return it to Zero on release Key 1 Answer


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