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
1
Question by bfbc2jb · Dec 29, 2012 at 05:09 AM · rotationcollisionjavatilt

Anti-Gravity vehicle bounce-back?

Hi Im making a game where you fly an anti gravity vehicle (ufo) using proper rigidbody physics not hackish transform.translate methods, the game is in like pre pre alpha so i dont know what im gonna do with it.

but the problem is.

when i activate the antigravity mode for the saucer, and start flying but when i collide into an object and the saucer tilts when collided, what i want to do is make the saucer automaticly bounce smoothly back when it tilts to its original rotation using proper rigidbody methods.

but i have no idea how to code that. thank you in advance, really apreciated.

Comment
Add comment · Show 1
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 Fattie · Jan 01, 2013 at 10:09 AM 0
Share

Looking forward to your new question !!!

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Fattie · Dec 29, 2012 at 09:25 AM

There are many ways to do this and they are all difficult ! Heh

You have chosen quite a challenge for your project.

One method: have an invisible UFO that flies along, and that is locked (look at your inspector, rigidbody, constrain) so that it stays straight and level.

Then, your "actual visible" UFO .. attach it with a Spring to the "actual invisible!" ufo. The "visible" ufo will bounce around nicely, but always come back to square and level in time.

This will produce one look that may be what you want.

The fact is - you'll have to master this technique and many others!


Another thing you will have to learn about is AddTorque

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddTorque.html

notice the various functions you have available to you here:

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.html

Just like you, I rarely use "hackish kinemantic" rubbish - I like to use "real many" physics! :) In fact you will have to get really good at using AddTorque. Basically you'll have to look at how the object is currently rotated, and apply a little torque against that. it's not easy but you can get there! Again - you'll have to master this technique and many others!


Now here's an example "UFO ATMOSPHERIC DRIVE" motion rig:

(1) Open Unity

(2) Make new project

(3) click "create cube"

(4) click on the cube. click "add rigidbody".

{As everyone knows, a typical UFO "weighs" about 900 kg {Reference .. "Above Top Secret", Timothy Good} Obviously, UFO engineering concepts include from the ground up modification of what we Earth scientists have recently laughably referred to as the "Higgs field" so you can't really just give the mass of a UFO in the atmosphere. But we can take 900kg as a good "simulation figure" when we are making a video game based on UFOs - so let's do that.}

(5) So in the Inspector, rigidbody, set Mass to 900 kg

(6) click "new javascript" Name it "teste.js" Paste in the entire script below... continued below

 /////////////////////////////////////////////////////////////////////////////
 
 // teste.js
 
 // example rig to make one aspect of ufo-like hovering motion
 
 // attach this to a CUBE WITH RIGIDBODY in Unity
 
 #pragma strict
 
 private var plusMinusStyleTwists:Vector3;
 
 function FixedUpdate()
     {
     plusMinusStyleTwists = transform.rotation.eulerAngles;
     
     plusMinusStyleTwists.x = _fix( plusMinusStyleTwists.x );
     plusMinusStyleTwists.y = _fix( plusMinusStyleTwists.y );
     plusMinusStyleTwists.z = _fix( plusMinusStyleTwists.z );
     
     plusMinusStyleTwists = -1 * 12.0 * plusMinusStyleTwists;
     
     rigidbody.AddTorque(
         plusMinusStyleTwists.x,
         plusMinusStyleTwists.y,
         plusMinusStyleTwists.z
         );
 
     }
 
 function _fix( tt:float )
     {
     // note that rotation.eulerAngles is just expressed as 0 to 360
     // of course we must change it to -180 to 180
     
     if ( tt > 180.0 ) return ( tt - 360.0 );
     return tt;
     }
 
 /////////////////////////////////////////////////////////////////////////////



(7) drag your Teste to the cube

(8) click Play

(9) click on the Cube

(10) click "E" on your keyboard

(11) notuce the three read circular draggables. grab the red one and disturb the cube about 20 degrees

(12) notice the Cube has an interesting behavior, it comes back to the middle. try disturbing all three of the circles and see how the Cube bounces around

(13) And now the critical part of the recipe. Click Stop. Look at the Inspector Rigidbody. Discover the ANGULAR DRAG one of the most important settings in a physics engine. It ranges form ZERO to ONE. Personally I like the highest setting for this ufo, 1.0

(14) note in the code i multiply the Degrees amount of "about 12". I just guessed that as a figure that works well for the 900 kg atmospheric mode UFO. Annoyingly, Unity/PhysX does not really (as far as I know) properly offer proper newton-metre (or even Joule-radians) measurement of Torque - so essentially I've just tooted around there with a rough and ready approach. In a real project you would use radians and do proper engineering.

Note too that I simply have a linear relationship from the angular disturbance to the "atmospheric mode balancer engine-like device" (AMBELD) in the UFO. Naturally, you would have to properly work out the response of an AMBELD and simulate that. (almost certainly it would decrease asymptotically, perhaps the 2nd or 3rd power, as it goes closer to true).

Finally this is of course a crappy solution that doesn't address gimbal lock, you'd have to take simple measures to avoid that problem.

Hope it helps get you started!

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

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Player Rotating after Collision... 0 Answers

animation help with falling when not grounded? 0 Answers

I made my code so that if i hit an enemy its health will go down but when i hit the enemy the health doesnt go down. please help 1 Answer

Rotating Sun? 4 Answers

stop player when it hits a wall 2d 0 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