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 sparkzbarca · Oct 10, 2012 at 09:34 PM · camerarotationphysicsrotatearound

rotate around with physics

Rotation issue.

trying to create halo forge like functionality to rotate a selected object. If I move the mouse up i'd like the bottom of the object to come towards the camera and the top to go away. Globally that is decrementing the Z axis rotation, but i'd like it to apply torque relative to the cameras Z axis, not its own local or global. I thought maybe using camera.transform.transformdirection might do it but I can't seem to implement it even though I feel like it should work in principle, Maybe transformdirection is wrong and i need some kind of transformrotation function?

I saw this solution

http://answers.unity3d.com/questions/133444/rotate-an-object-relative-to-a-camera.html

however I want to use rigidbody not transform so that if I rotate into another object it will collide.

I've honestly been trying for a few hours now to hammer out a solution and its not coming to me. Help would be much appreciated. Thank you.

alt text

rotation.png (23.6 kB)
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
Best Answer

Answer by Sisso · Oct 11, 2012 at 02:41 AM

To rotate a RigidBody you must apply Torque Force (http://en.wikipedia.org/wiki/Torque).

Will be some complications when you try tu control a object rotation using forces cause its inercia. Take a look on this thread, implement and use a PID controller is easier than it seem.

http://answers.unity3d.com/questions/197225/pid-controller-simulation.html

Editted:

A sample code that I think that rotate an object in Y axis using torqueForce. It must be tested and expanded to X/Z axis. I have simplified the PID controller by a simple weight.

 var weightDistance = 0.1;
 var weightSpeed = 0.1;
 
 var angularDistanceForTarget  = Vector3.Angle(targetDir, forward);
 var angularVelocity = rigidbody.angularVelocity.y;
 
 var mod = (angularDistanceForTarget * weightDistance) - (angularVelocity * weightVelocity);
 var force = maxTorqueForce * Mathf.Clamp(mod, -1, 1);
 rigidbody.AddTorque (Vector3.up * force);


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 sparkzbarca · Oct 11, 2012 at 09:24 PM 0
Share

Yea its annoying that there isn't a kind of simple physics which allows you to move objects without forces but with colliders.

I think though i'm just going to turn freeze/iskinematic off and on quick to remove applied forces. Your essentially constructing stuff just like forge. Its seperate from the game itself so i'm not worried about the implications of things changing there states.

avatar image Sisso · Oct 12, 2012 at 03:24 PM 0
Share

The problem is that if you want to simulate the real world, you must to use real world rules. :P I have edited my answer added a sample pseudo code.

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

10 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

Related Questions

How can I rotate around with a Rigidbody while respecting physics? 0 Answers

Look in movement direction 0 Answers

How to limit the angle of a camera with transform.RotateAround? 1 Answer

An alternative to RotateAround for collisions 0 Answers

Limit camera rotation with RotateAround 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