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 DEADmetal · Mar 24, 2014 at 09:23 AM · rotationlocalrotationangularvelocity

C# - local angularVelocity

Hello, i've been asking this question few times already. I wonder if it's that hard or no one answers for some other reason.

I need to detect objects rotation in local axis. Not to make it rotate in local axis but to detect its rotation in local axis.

My code:

if (Spaceship.rigidbody.angularVelocity.z > 0)

It does what i need but only in respect to worlds axis.

Thanks for the help.

Comment
Add comment · Show 3
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 DEADmetal · Mar 24, 2014 at 01:52 PM 0
Share

Come on guys. Don't you know the solution to this see$$anonymous$$gly simple problem? Where are you pros?

avatar image Lo0NuhtiK · Mar 24, 2014 at 01:54 PM 1
Share

$$anonymous$$aybe no one is answering in this topic because of :

Hello, i've been asking this question few times already.

avatar image Berenger · Mar 24, 2014 at 02:03 PM 0
Share

You are mixing up the rotation of the object, meaning the current quaternion applied to it, with the velocity (how fast it turns). Which one do you really need ?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Mar 24, 2014 at 03:06 PM

This should work:

 var localAngularVelocity = transform.InverseTransformDirection(Spaceship.rigidbody.angularVelocity);

Note that Rigidbody.angularVelocity is in radians. Shouldn't matter if all you are doing is testing against 0.0.

Comment
Add comment · Show 12 · 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 DEADmetal · Mar 24, 2014 at 03:54 PM 0
Share

Could you please incorporate that to my code? I have no idea where that should go.

I've tried as follows:

var localAngularVelocity = transform.InverseTransformDirection(rigidbody.angularVelocity); if (-localAngularVelocity.z > 0) rigidbody.AddForce (-transform.up * 500);

And the result is still dependant on the direction that "Spaceship" is facing. Thanks for your answer tho.

avatar image robertbu · Mar 24, 2014 at 04:06 PM 1
Share

Your code looks fine, so I believe it gives you what you asked for, but perhaps not what you need. In particular, there is no guarantee that the rotation you want will be represented in the way you expect. Can you describe what you are trying to achieve?

avatar image DEADmetal · Mar 24, 2014 at 04:30 PM 0
Share

I will try.

It is the base part of my flight control system for the spaceship. The flight control system should kill any rotation by detecting the rotation and firing appropriate thrusters.

Yes i could have done it the simple way, i could have just made the spaceship rotate by itself and have angular drag but my project is spaceship simulator.

So again, basically, i want the code to check if there is any angular speed, on which axis and to which direction. It perfectly does that but not the last part - it ignores local (spaceship) axis and uses world axis so if the spaceship is facing another way, the rotation is accelerated ins$$anonymous$$d of stopped.

I hope i've made it clear now.

Thanks for your help man.

avatar image robertbu · Mar 24, 2014 at 04:49 PM 0
Share

You made it clear(er), but I cannot see how 'AddForce()' on the same object that you are using for calculating the angular velocity will impact the angular velocity at all. That is the force will be applied to the center of mass which is also the center about which this object is rotating. You will need an AddForceAtPosition() or some other way to offset the force from the center of mass. And if you do that, I don't believe you want the local angular velocity.

avatar image DEADmetal · Mar 24, 2014 at 04:55 PM 0
Share

The "Spaceship" is a separate object from that to which AddForce line applies. The object is another rigidbody (a thruster) on the side of the spaceship so it stops the rotation with applied force to it.

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

22 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

Related Questions

Child versus Parent rotations 3 Answers

how to apply overall rotation to collection of rotated objects 0 Answers

Maintain world rotation on parenting to another object 0 Answers

Get the Inspector's rotation of an object with code 0 Answers

Importing a armature from blender to unity ruins the models rotations -1 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