• 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 DevMerlin · Jun 08, 2016 at 04:05 AM · c#physics

C# - How can I flip my rotation - smoothly and slowly - by 180 degrees using torque in physics?

I am trying to figure out how to write a bit that will flip my model's rotation using physics by exactly 180 degrees. However, this needs to happen -slowly-, not instantly. What I have is an 180 that travels back and forth on a 2.5D screen. Each time it hits a waypoint, it needs to determine if it has to move and turns on the Y axis to face the new waypoint. If it's already facing it, it simply continues on.

I have been using .dot to determine where the waypoint is and rotate, but I'm not sure if that's the best way to do it:

  Vector3 Heading = TargetLocation - transform.position;
  float direction = Vector3.Dot(Heading, -transform.forward);

Can anyone suggest another method? It needs to be physics-compatible.

EDIT:

I've found a possible solution, however it completely ignores targets that are directly behind it. Can anyone figure out why it's doing so? If needed I can post this to another question as well

   TargetLocation = TempTarget.position;
   Vector3 Heading = TargetLocation - transform.position;
 
   Vector3 Rotate = Vector3.Cross(-transform.up, (Heading).normalized) * 200;
 
   boatRB.AddTorque(Rotate);

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
0
Best Answer

Answer by DevMerlin · Jun 08, 2016 at 01:27 PM

I fixed it with a bit of a hack. I created a "Steering wheel" primitive set with a circle and a target point on that circle. The vehicle pays attention to the target point and rotates the circle towards the desired degree. It then follows the target point as it moves around the circle to the correct orientation - which also creates a balancing and self-correcting effect should it get hit.

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 _Yash_ · Jun 08, 2016 at 04:43 AM

You can do this by changing angularVelocity

 Vector3 Heading = TargetLocation - transform.position;
 float direction = Vector3.Dot(Heading, -transform.forward);
 direction = direction * speed; // change speed value to get the acceptable effect(smooth/fast).
 rigidbody.angularVelocity = new Vector3( 0f, direction, 0f );
 
 
 
Comment
Add comment · Show 3 · 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 DevMerlin · Jun 08, 2016 at 04:44 AM 0
Share

Will this affect current rotations - like bobbing effects too much?

avatar image DevMerlin · Jun 08, 2016 at 04:51 AM 0
Share

Unfortunately it does, it'll negate the bobbing effect I have working with a buoyancy script. That's why I want to work this out using torque.

avatar image _Yash_ DevMerlin · Jun 08, 2016 at 01:25 PM 0
Share

applying torque will change the rigidbody's angularVelocity at the end.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

168 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

2d game platform physics 1 Answer

How to change CC script to Rigidbody script 1 Answer

OnJointBreak 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