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 thenachotech1113 · May 26, 2014 at 03:51 AM · inertiaenergydampingcancel

How to do inertia damping

If you have ever played Space Engineers you shoudl be familiar with how inertia damping works, if not, its basically a toggle mechanism that allows you to cancel undesired energy(any energy that is not the one that not in the direction you are heading. if not pressing any movement key, it cancels all energy). this works in space where there should be low friction. i can't just add a certain amount of drag to cancel most of undesired movement since that would also cancel all the desired energy. so that prety much leaves me with coding and i have no idea on how to do it. please not I am not asking nor wanting any of you to write a script for me but simply to give me ideas on how to do this since I dont have a clue. thanks to all, i appreciate all your help.

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

Answer by supernat · May 26, 2014 at 04:50 AM

I think you have to code this either way, but there's no limitation of the engine that would prevent you from just increasing drag. SE actually applies forces in the opposite directions with varying thruster flame sizes, so that wouldn't be so easily simulated by just increasing drag.

It's really fairly simple. You just calculate your forward moving velocity (let's assume for a minute that you can't move the camera, it always faces forward), then compute the x and y values in the local body coordinates that make up that velocity. For instance, let's say your velocity in world coordinates is 10.0, 0, 10.0, so you are moving at a 45 degree angle down the X/Z plane. You just need to apply -10.0 force in the world X direction at the same time applying -10.0 force in the world Z direction (i.e. just negate the velocity vector (oh but also do it in small amounts, otherwise it would stop immediately)). But if you want it to look realistic or handle moving in one direction while pointing in a different direction, you have to figure out what thrust amounts forward, right, and down (from your body's perspective) would equivalence to -10.0, -10.0 X/Z thrust. I hope that makes sense.

It's just a coordinate transform at that point. If you make the forward velocity (in world coordinates) a unit vector (i.e. a direction cosine), you can rotate that vector by applying the inverse transform for the body to world matrix. Or just multiply your vector by the Transform's worldToLocal matrix, which will put your (-10.0, 0, -10.0) world vector into body (local) coordinates. Then you can set the flame size coming out of your thruster pack on the front of your body, the side of your body, and whatever it does for up/down, based on the size of each component in the new vector. You then multiply the new vector (i.e. the body direction cosine vector) by the original forward velocity magnitude, and that will give you the velocity relative to your body. So, for instance if you were moving due north along the +Z axis, but you rolled the camera around to look behind you, you would still be moving in the +Z axis (0, 0, 1) direction cosine. But from your body's (camera's) perspective, you are moving backwards (0, 0, -1).

I know you didn't ask for code, but maybe this will help clear up my mumble jumble.

 Vector3 velocity = new Vector3(10, 0, 10);

 void Update {
     // What direction are we moving?
     Vector3 worldDir = velocity.normalized;

     // Convert velocity to direction, then from world coordinates to local coords
     Vector3 localDir = -transform.InverseTransformDirection(worldDir);
     // Do whatever with localDir.x, and localDir.z to simulate thruster fuel burn
     velocity -= 0.05f*Time.deltaTime*worldDir;
     // Add some logic to check if velocity is near zero and shut down all of this code
 }

In this case, I just used the convenience method InverseTransformDirection, and there really wasn't any need to compute a local velocity, reduce it by the local value, and convert that local value back to world coordinates, because it will do essentially the same thing as just reducing the original world velocity by some small amount. For a more realistic appearance, adjust the 0.05f constant based on the thruster outputs and how much inertia you need to dampen. As your velocity approaches zero, you would reduce 0.05 more and more, and as it increases, you would increase it but limit it to some max value as the thrusters can only put out so much force.

Comment
Add comment · Show 1 · 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 thenachotech1113 · May 27, 2014 at 02:12 AM 0
Share

Thanks a lot for taking your time to answer my question, it has been really useful.

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

How to add inertia damping? 1 Answer

What does the "compute mesh inertia tensor failed" error mean? 6 Answers

Why am I being asked to change the mesh geometry or supply a tensor manually? 1 Answer

Healthbar Energy Bar and MiniMaps? 0 Answers

2d rigidbody stops on collision if velocity smaller than 1 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